Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
269 views
in Selenium by
recategorized by
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 like 0 dislike
by
selected by
 
Best answer
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


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...