Issue
In my test some of the elements which are located via a css selector
take a long time to appear as the servers are very slow. I often get this error when running the tests through jenkins but not locally on eclipse.
> org.openqa.selenium.TimeoutException: Expected condition failed:
> waiting for visibility of element located by By.cssSelector:
> #ctl00_ContentPlaceHolder1_uctlSettingUpPaymentCollectionGrid1_gvGroup_ctl02_deleteGroup
> (tried for 10 second(s) with 500 milliseconds interval)
Is it possible to increase this to more then 10 seconds on selenium?
Solution
Try implicit waits - docs here
There is a second type of wait that is distinct from explicit wait called implicit wait. By implicitly waiting, WebDriver polls the DOM for a certain duration when trying to find any element. This can be useful when certain elements on the webpage are not available immediately and need some time to load.
You set it once for your driver and it's a dynamic wait up until your specified timeout.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Alternatively, you can use explicit waits per element that needs it:
new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.elementToBeClickable(<<Your-Identifier>>));
With explicit waits you can ensure certain ExpectedConditions are ready and you control the timeout for the element to synchronise with.
A list of expected conditions for Java are here
It is generally recommended you choose on approach if possible:
Warning: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example, setting an implicit wait of 10 seconds and an explicit wait of 15 seconds could cause a timeout to occur after 20 seconds.
Answered By - RichEdwards