Selenium With Java and Python For Mobile Apps & Web Apps......!

Wednesday, 8 April 2015

Wait Statement in Selenium Webdriver.

Wait Statement during Navigation:



Thread.sleep(5000) Wait For 5 Seconds using Java API

Implicitly Wait Command:Implicit wait statement used wait till entire page get download
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);


Expected Conditions Commands:Explicit wait statement used to load web element not entire page used in dynamic app(ajax app)

WebDriverWait wait=new WebDriverWait(driver,30);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("add project")));

FluentWait Command:An implementation of the Wait interface that may have its timeout and polling interval configured on the fly. Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page

->:Waiting 30 seconds for an element to be present on the page, checking
->: for its presence once every 5 seconds.
  
  Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
       .ignoring(NoSuchElementException.class);

   WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
     public WebElement apply(WebDriver driver) {
       return driver.findElement(By.id("foo"));
     }

   });

Set ScriptTimeoutSet the amount of time to wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.

driver.manage().timeouts().setScriptTimeout(100,SECONDS);
PageLoadTimeout:Set the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.


driver.manage().timeouts().pageLoadTimeout(100, SECONDS);

0 comments:

Post a Comment

Translate

Popular Posts

Total Pageviews