A Test failure after upgrading Selenium 3 to 4

274 Views Asked by At

I have upgraded the application from selenium 3 to selenium 4 and found that some of the test cases getting failed after upgradation with below error message.

com.thoughtworks.selenium.SeleniumException: Timed out waiting for action to finish
at com.thoughtworks.selenium.webdriven.Timer.run(Timer.java:46)
at com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:181)
at com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:95)
at com.thoughtworks.selenium.DefaultSelenium.waitForPageToLoad(DefaultSelenium.java:816)

The test cases are getting failed on below line.

SeleniumSession.get().waitForPageToLoad();

SeleniumSession is internal class which is extending DefaultSeleniumSession class

The default timeout configured for these test cases is 3 min.

Can you please help to understand how we can fix this issue. Or do we have any alternate method in selenium 4 to achieve the waitForPageToLoad.

Thanks.

1

There are 1 best solutions below

2
Akzy On

If you are getting this error you may use the WebDriverWait like below

WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//your/xpath/here")));

OR

You can use the PageLoadStrategy that introduce in selenium 4. Like below

ChromeOptions options = new ChromeOptions();
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
WebDriver driver = new ChromeDriver(options); 

You can also combine the above both and use it like this

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.urlContains("example.com"));

You can read more about the PageLoadStrategy from here

import

import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;