Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
Can anyone help me with selenium webdriver wait commands best practices?

Solved 1 Answers 63 Views Selenium
0 1
I am new to Selenium. I am using PageObject model. I would like to know the best practices for using WebDriverWait commands

1 Answer

0
Best answer
0
ImplicitlyWait
 
driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);
 
ExplicitWait
 
WebElement oneWayRadioButton = wait.until(ExpectedConditions.elementToBeClickable(By.id(YOUR_Locator)));
oneWayRadioButton.click();
 
 
pageLoadTimeout
 
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
 
setScriptTimeout
 
driver.manage().timeouts().setScriptTimeout(100, TimeUnit.SECONDS);
 
You need to call ignoring with exception to ignore while the WebDriver will wait.
 
// Waiting 30 seconds for an element to be present on the page, checking // for its presence once every 5 seconds.
 
try{
   WaitWebDriver wait = new FluentWaitWebDriver(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
    }catch(NoSuchElementException ignore)   {}
 
   WebElement foo = wait.until(new FunctionWebDriver, WebElement() {
     public WebElement apply(WebDriver driver) {
       return driver.findElement(By.id(YOUR_Locator));
     }
   });
 
You may even use 
 
Thread.sleep(timeoutsec*1000);
 
However using Thread.sleep is not the best practices
answered by
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...