selenium 3 frame switching doesn't work - How to fix without a retry mechanism

51 Views Asked by At

After login I am trying to click Switch button from menu tab. This button is part of a frame. After clicking it, the page is loaded but elemnt switchToProduction can not be found. It seems that driver contains old control frame.

console.warn: services.settings: Allow by setting MOZ_REMOTE_SETTINGS_DEVTOOLS=1 in the environment
console.error: (new TypeError("lazy.AsyncShutdown.profileBeforeChange is undefined", "resource://services-settings/Database.sys.mjs", 599))
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of any elements located by By.id: switchToProduction (tried for 5 second(s) with 500 milliseconds interval)
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
    at test.Test2.main(Test2.java:39)
Caused by: org.openqa.selenium.NoSuchWindowException: Browsing context has been discarded
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'uk2prdd21846', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.102.1.el7.x86_64', java.version: '1.8.0_341'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 115.4.0, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20231018093353, moz:geckodriverVersion: 0.33.0, moz:headless: false, moz:platformVersion: 3.10.0-1160.102.1.el7.x86_64, moz:processID: 8735, moz:profile: /tmp/rust_mozprofile11C1Wj, moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, moz:windowless: false, pageLoadStrategy: normal, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 769f8749-d169-4169-a0e0-bf4fcc429ea1
*** Element info: {Using=id, value=switchToProduction}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    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.findElements(RemoteWebDriver.java:353)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementsById(RemoteWebDriver.java:376)
    at org.openqa.selenium.By$ById.findElements(By.java:180)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:311)
    at org.openqa.selenium.support.ui.ExpectedConditions$11.apply(ExpectedConditions.java:328)
    at org.openqa.selenium.support.ui.ExpectedConditions$11.apply(ExpectedConditions.java:325)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)

I am using selenium 3.141.59, geckodriver 0.33 and firefox 113. Here is my code:

        System.setProperty("webdriver.gecko.driver", "geckodriver");
//        System.setProperty("webdriver.chrome.driver", "chromedriver");

        FirefoxOptions options = new FirefoxOptions();
        options.setLogLevel(Level.FINEST);
        WebDriver driver = new FirefoxDriver(options);

        driver.get("myurl");

        //login
        driver.findElement(By.id("username")).sendKeys("user");
        driver.findElement(By.name("password")).sendKeys("password");
        driver.findElement(By.id("login")).click();

        WebDriverWait wait = new WebDriverWait(driver, 5);

        //click Switch button from control frame
        driver.switchTo().defaultContent();
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("control")));
        wait.until(ExpectedConditions.elementToBeClickable(By.id("switchToTest")));
        driver.findElement(By.id("switchToTest")).click();

        //check that after Switch button is pressed, Switch to Production button is present in "control" frame
        driver.switchTo().defaultContent();
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("control")));
        wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.id("switchToProduction")));

        driver.quit();
    }
}

pom.xml

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>3.141.59</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

With chromedriver everything looks fine. Also with selenium2.

I tried all types of wait mechanism but nothing solve my issue

0

There are 0 best solutions below