Home > Net >  JAVA Selenium iFrame issues: click() is looking for active frame but frame changed during click meth
JAVA Selenium iFrame issues: click() is looking for active frame but frame changed during click meth

Time:04-07

I am currently testing the UI of a PEGA application whereas I have stumbled on an issue where I am clicking a button that in its turn saves an item and closes the frame. When click method is finished it is still looking for frame y but stands on frame x, so it crashes.

The issues followed by this is when using:

driver.findElement(By.x("selector")).click(); 

frame is switching and in the framework its still trying to locate the previous active frame (which is not visible at this time).

Im on frame PegaGadget2Ifr but ends up on PegaGadget1Ifr curing click.

This is what code im running:

    public void saveProjectAsDraft(){
        Project_page pp = new Project_page(FDMPortal.getActiveFrameId(true), testEnv);
        FDMObjectsBean.setProject_page(pp);
        pp.saveDraft();
    }

public Workplace_details_page saveDraft(){
        findElement(SAVE_DRAFT).click();
        return new Workplace_details_page(getActiveFrameId(true),testEnv);
    }

getting this error message.

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#PegaGadget2Ifr"}
  (Session info: chrome=99.0.4844.74)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
os.version: '10.0', java.version: '1.8.0_312'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 99.0.4844.74, chrome: {chromedriverVersion: 99.0.4844.51 (d537ec02474b5..., userDataDir: x, goog:chromeOptions: {debuggerAddress: localhost:63949}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: x
*** Element info: {Using=id, value=PegaGadget2Ifr}
    at sun.reflect.GeneratedConstructorAccessor16.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)
    at org.openqa.selenium.By$ById.findElement(By.java:188)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
    at com.pega.framework.PegaWebDriverImpl.switchToActiveFrame(PegaWebDriverImpl.java:613)
    at com.pega.framework.PegaWebElementImpl.click(PegaWebElementImpl.java:513)
    at com.pega.framework.PegaWebElementImpl.click(PegaWebElementImpl.java:407)
    at com.pega.crm.workobjects.Project_page.saveDraft(Project_page.java:166)
    at stepdefs.WorkplaceStepDefs.saveProjectAsDraft(WorkplaceStepDefs.java:390)```

CodePudding user response:

First switch to the frame where the element is present and then perform activity on the element. Use one of the available method

switchTo().frame(Index)
switchTo().frame(Web Element)
switchTo().frame(Id or name)

CodePudding user response:

As the previous frame PegaGadget2Ifr closes, an ideal approach would be to switch to the default Content first:

driver.switchTo().defaultContent();

and then attempt to switch to PegaGadget1Ifr frame.

  • Related