Methods selenium waiting time

First, forced to wait for a fixed number of seconds

1 try {
2             Thread.sleep(1000);
3         } catch (InterruptedException e) {
4             e.printStackTrace();
5         }

When performing the sleep () method, a fixed sleep seconds, milliseconds ms-- units, commonly used when debugging code

Second, implicit wait

1 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Implicit wait:

1, waiting for a more flexible approach to find the page elements will be down, can not find it waiting more than a specified time to throw an exception

2, implicit wait scope is global, i.e., all the elements in the page are set waiting time; until the driver instance is closed, to wait before failure

Third, the explicit wait

1 WebDriverWait wait =new WebDriverWait(driver, 10);
2 wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("OK")));
3 driver.findElement(By.linkText("OK")).click();
ExpectedConditions common method detailed in this article: 

Click here

Explicit waiting:

1, explicitly set the wait time to wait for a certain element on the page

2, if the elements found within the specified time to perform the related operations, if more than the set time does not detect an exception is thrown

 

In doing automation long common way is to wait for an explicit wait

 

Guess you like

Origin www.cnblogs.com/zddwork/p/11411597.html