0% found this document useful (0 votes)
3 views8 pages

Selenium Waits: Test Automation Basics With Selenium & Java

The document discusses Selenium waits, comparing implicit and explicit waits, and their importance in test automation using Java. It explains how implicit waits pause until an element is displayed, while explicit waits allow for customizable timeouts and flexible event handling. The document also provides a custom wait example and outlines steps for a test scenario involving Google search functionality.

Uploaded by

sxoterry
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Selenium Waits: Test Automation Basics With Selenium & Java

The document discusses Selenium waits, comparing implicit and explicit waits, and their importance in test automation using Java. It explains how implicit waits pause until an element is displayed, while explicit waits allow for customizable timeouts and flexible event handling. The document also provides a custom wait example and outlines steps for a test scenario involving Google search functionality.

Uploaded by

sxoterry
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Selenium Waits

Test automation basics with Selenium & Java


By:
Evgeny Novikov
Email:
xevgnov@[Link]
Waits VS sleeps
● [Link](1000) - stops program execution to 1 second
● WebDriverWait waits for some event

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Selenium waits
● Implicit wait

● Explicit wait

● Fluent wait

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Implicit wait
- waits till element will be displayed on a page
- waits till timeout
- if element was not found, it throws:
[Link]: no such
element
Example:
[Link]().timeouts().implicitlyWait(30,
[Link]); By:
Evgeny Novikov
Email:
xevgnov@[Link]
Explicit wait
1) customizable timeout Example:
2) flexible wait for events: WebDriverWait wait = new
● element's presence WebDriverWait( driver, 30);
[Link](
● element (in-)visibility ExpectedConditions

● till page loaded .elementToBeClickable(searchButton));

● till alert displayed


● till Javascript returns some value
By:
Evgeny Novikov
Email:
xevgnov@[Link]
Do not mix implicit and explicit waits
if you use explicit waits,
then implicit wait should not be used be or set to ‘0’

● implicit wait equals 0 by default,


● it could be set to zero manually:
[Link]().timeouts().implicitlyWait( 0, TimeUnit. SECONDS);

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Custom wait example
boolean isElementDisplayed(By by, int timeout) throws
InterruptedException {
List<WebElement> elements = [Link](by);
for(int i = 0; (i < timeout) && ([Link]() == 0); i++) {
Thread. sleep(1000);
elements = [Link](by);
}
return [Link]() > 0;
}

By:
Evgeny Novikov
Email:
xevgnov@[Link]
Create test with following steps:
- Open [Link]
- wait until page header will be
visible
- wait until search button will be
clickable
Exercise - type some string in search field
- press search button
- verify that search page header
Add to test explicit wait, until is invisible on results page
chosen element would not be Hint:
visible. use
[Link](el
ement)); By:
Evgeny Novikov
Email:
xevgnov@[Link]

You might also like