SlideShare a Scribd company logo
YOU ARE DOING IT WRONG
ALL THE TIME
The Great Battle of Selenium Waits
Speaker Info
Yaroslav Pernerovsky,
Ukraine
Automation Team Lead,
GlobalLogic
/in/yaroslav-pernerovsky-0559b51
/yaroslav.pernerovsky
Problem
Implicit waits are a terrible mistake I've made
and I apologies for them
Simon Stewart, d
Creator of WebDriver
Problem
Problem
Problem
Problem
@Test
public void simpleAction() {
driver.get("http://www.google.com");
driver.findElement(By.name("q"))
.sendKeys("Search String" + Keys.ENTER);
driver.findElement(By.cssSelector("h3.r"))
.click();
}
Real Case
Real Case
Real Case
Custom Wait
while(true) {
if (System.currentTimeMillis()-startTime > timeout){
throw new TimeoutException();
}
try {
return driver.findElement(locator);
}
catch (NoSuchElementException e) {}
Thread.sleep(500);
}
WebDriver waits
chromedriver
geckodriver
IEDriverServer
Implicit waits hereExplicit waits here
Implicit Waits
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
Implicit Waits
driver.findElement()
• Wait until element appeared in DOM
• Return first element if more than one present
• Throws NoSuchElementException
Implicit Waits
driver.findElements()
• Wait until at least one element appeared in DOM
• Return collection of all found elements
• Return empty collection if no elements found
Implicit Waits Common Issue
public boolean isElementPresent(By locator) {
return driver.findElements(locator).size() > 0;
}
if (isElementPresent(login))
driver.findElement(login).click();
if (!isElementPresent(login))
driver.findElement(logout).click();
Implicit Waits Common Issue
public boolean isElementNotPresent(By locator) {
driver.manage().timeouts()
.implicitlyWait(0, TimeUnit.SECONDS);
boolean result= driver.findElements(locator).size() > 0;
driver.manage().timeouts()
.implicitlyWait(defaultTimeOut, TimeUnit.SECONDS);
return result;
}
Explicit Waits
WebDriverWait wait = new
WebDriverWait(driver, 10);
wait.until(driver ->
driver.findElement(locator));
wait.until(ExpectedConditions
.presenceOfElementLocated(locator));
http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
What's wrong?
wait.until(driver ->
driver.findElement(locator));
WebDriver Exceptions and RemoteWebDriver
Solution?
wait.until(driver ->
driver.findElements(locator).size() > 0);
Mixed waits issues
What if?
wait = new WebDriverWait(driver,5);
driver.manage().timeouts()
.implicitlyWait(10, TimeUnit.SECONDS);
wait.until(ExpectedConditions
.presenceOfElementLocated(locator);
How long will Selenium wait ?
5 15
C: 10 25
Why?
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) {
return new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
return findElement(locator, driver);
}
...
private static WebElement findElement(By by, WebDriver driver) {
try {
return driver.findElements(by).stream().findFirst().orElseThrow(
() -> new NoSuchElementException("Cannot locate an element using " + by));
} catch (NoSuchElementException e) {
throw e;
} catch (WebDriverException e) {
log.log(Level.WARNING,
String.format("WebDriverException thrown by findElement(%s)", by), e);
throw e;
}
}
What if?
wait = new WebDriverWait(driver,5);
driver.manage().timeouts()
.implicitlyWait(10, TimeUnit.SECONDS);
wait.until(ExpectedConditions
.presenceOfElementLocated(locator);
Which exception will be thrown ?
A: Timeout NoSuchElement
Both None
What if?
wait = new WebDriverWait(driver,10);
driver.manage().timeouts()
.implicitlyWait(5, TimeUnit.SECONDS);
wait.until(ExpectedConditions
.presenceOfElementLocated(locator);
How long will Selenium wait ?
5 15
C: 10 25
What if?
wait = new WebDriverWait(driver,11);
driver.manage().timeouts()
.implicitlyWait(5, TimeUnit.SECONDS);
wait.until(ExpectedConditions
.presenceOfElementLocated(locator);
How long will Selenium wait ?
5 B: 15
11 26
What if?
wait = new WebDriverWait(driver,5);
driver.manage().timeouts()
.implicitlyWait(10, TimeUnit.SECONDS);
wait.until(ExpectedConditions.not(
ExpectedConditions.presenceOfElementLocated(locator));
How long will Selenium wait if element is present?
A: 5 15
10 25
What if?
wait = new WebDriverWait(driver,5);
driver.manage().timeouts()
.implicitlyWait(10, TimeUnit.SECONDS);
wait.until(ExpectedConditions.not(
ExpectedConditions.presenceOfElementLocated(locator));
How long will Selenium wait if element is not present?
C:
5 15
10 25
Coexistence rules
Use Implicit wait for element presence
Do not use Explicit wait for element presence
Always set implicit timeout lower than explicit
Timeouts must be multiple to each other
Take special care to 'not present' conditions
Side-by-Side comparison
Client Side (500ms)
Can wait for anything
Explicit usage
TimeoutException
Multiple network calls
Explicit Implicit
Driver Side (100ms)
Element appeared in DOM
Works automatically
NoSuchElementException
Single network call
Few words about Selenide
WebDriver Implicit Wait not used at all
Custom implicit waits on client side
Default polling interval - 100ms
Remote WebDriver traffic issues
Questions

More Related Content

What's hot (20)

PPTX
Introduction to selenium
Archana Krushnan
 
PDF
PUC SE Day 2019 - SpringBoot
Josué Neis
 
PDF
Spring Boot
Pei-Tang Huang
 
PPTX
Introduction to Selenium Web Driver
Return on Intelligence
 
PPT
05 junit
mha4
 
PPTX
WebdriverIO: the Swiss Army Knife of testing
Daniel Chivescu
 
PPTX
JUnit- A Unit Testing Framework
Onkar Deshpande
 
PPT
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
PPT
Selenium Automation Framework
Mindfire Solutions
 
PDF
Mobile Test Automation - Appium
Maria Machlowska
 
DOCX
Katalon studio vs selenium comparision
Prabhusundar6
 
PPTX
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
Simplilearn
 
PPTX
Appium overview
Abhishek Yadav
 
PDF
Spring Boot
koppenolski
 
PPTX
React JS part 1
Diluka Wittahachchige
 
PPTX
Test Automation Using Selenium
Nikhil Kapoor
 
PPT
Selenium Presentation at Engineering Colleges
Vijay Rangaiah
 
PDF
웹 Front-End 실무 이야기
JinKwon Lee
 
PDF
Waits in Selenium | Selenium Wait Commands | Edureka
Edureka!
 
PDF
Web application testing with Selenium
Kerry Buckley
 
Introduction to selenium
Archana Krushnan
 
PUC SE Day 2019 - SpringBoot
Josué Neis
 
Spring Boot
Pei-Tang Huang
 
Introduction to Selenium Web Driver
Return on Intelligence
 
05 junit
mha4
 
WebdriverIO: the Swiss Army Knife of testing
Daniel Chivescu
 
JUnit- A Unit Testing Framework
Onkar Deshpande
 
QSpiders - Automation using Selenium
Qspiders - Software Testing Training Institute
 
Selenium Automation Framework
Mindfire Solutions
 
Mobile Test Automation - Appium
Maria Machlowska
 
Katalon studio vs selenium comparision
Prabhusundar6
 
What Is Selenium? | Selenium Basics For Beginners | Introduction To Selenium ...
Simplilearn
 
Appium overview
Abhishek Yadav
 
Spring Boot
koppenolski
 
React JS part 1
Diluka Wittahachchige
 
Test Automation Using Selenium
Nikhil Kapoor
 
Selenium Presentation at Engineering Colleges
Vijay Rangaiah
 
웹 Front-End 실무 이야기
JinKwon Lee
 
Waits in Selenium | Selenium Wait Commands | Edureka
Edureka!
 
Web application testing with Selenium
Kerry Buckley
 

Similar to Implicit and Explicit waits in Selenium WebDriwer, how to. (20)

PDF
WebDriver Waits
Yaroslav Pernerovsky
 
PPT
Java. Explicit and Implicit Wait. Testing Ajax Applications
Марія Русин
 
PDF
waits.pdf
ssuser0562f1
 
PPTX
Different wait methods or commands in Selenium
Vinay Kumar Pulabaigari
 
PDF
waits.pdf
ssuser0562f1
 
PDF
Automation puzzlers
Yaroslav Pernerovsky
 
PDF
How to Use Selenium Waits_ A Step-by-Step Guide.pdf
Steve Wortham
 
PPTX
Handling Exceptions and waits in selenium.pptx
Madhuri Lonikar
 
PPTX
Selenium inputs
KadarkaraiSelvam
 
PPTX
Waits alerts and switch windows
Ducat
 
PPTX
Synchronization in Selenium WebDriver
SHUBHAM PATIL
 
PPTX
2016 - Fail Proof Ways to Run Beautiful Tests Regardless Of Browser Choice
devopsdaysaustin
 
PPTX
Web driver training
Dipesh Bhatewara
 
PDF
Build Fail-Proof Tests in Any Browser with Selenium
TechWell
 
PDF
Web ui testing
Radim Pavlicek
 
PPTX
2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on!
Alfonso Peletier
 
PPTX
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Edureka!
 
PPTX
Challenges in test automation for web apps
Sudara Fernando
 
PPTX
Presentation(Q3).pptxgdfgfgwdfwgdfwgdfwgdfwwwgsvwgdvgdvgdvwg
utsavaggarwal8
 
PPTX
Being good at waiting - Using Selenium to test Ajax-intensive pages
Alexander Tarlinder
 
WebDriver Waits
Yaroslav Pernerovsky
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Марія Русин
 
waits.pdf
ssuser0562f1
 
Different wait methods or commands in Selenium
Vinay Kumar Pulabaigari
 
waits.pdf
ssuser0562f1
 
Automation puzzlers
Yaroslav Pernerovsky
 
How to Use Selenium Waits_ A Step-by-Step Guide.pdf
Steve Wortham
 
Handling Exceptions and waits in selenium.pptx
Madhuri Lonikar
 
Selenium inputs
KadarkaraiSelvam
 
Waits alerts and switch windows
Ducat
 
Synchronization in Selenium WebDriver
SHUBHAM PATIL
 
2016 - Fail Proof Ways to Run Beautiful Tests Regardless Of Browser Choice
devopsdaysaustin
 
Web driver training
Dipesh Bhatewara
 
Build Fail-Proof Tests in Any Browser with Selenium
TechWell
 
Web ui testing
Radim Pavlicek
 
2016 09-09 - Selenium Webdriver - Fundamentals + Hands-on!
Alfonso Peletier
 
Selenium Interview Questions and Answers | Selenium Tutorial | Selenium Train...
Edureka!
 
Challenges in test automation for web apps
Sudara Fernando
 
Presentation(Q3).pptxgdfgfgwdfwgdfwgdfwgdfwwwgsvwgdvgdvgdvwg
utsavaggarwal8
 
Being good at waiting - Using Selenium to test Ajax-intensive pages
Alexander Tarlinder
 
Ad

Recently uploaded (20)

PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Ad

Implicit and Explicit waits in Selenium WebDriwer, how to.

  • 1. YOU ARE DOING IT WRONG ALL THE TIME The Great Battle of Selenium Waits
  • 2. Speaker Info Yaroslav Pernerovsky, Ukraine Automation Team Lead, GlobalLogic /in/yaroslav-pernerovsky-0559b51 /yaroslav.pernerovsky
  • 3. Problem Implicit waits are a terrible mistake I've made and I apologies for them Simon Stewart, d Creator of WebDriver
  • 8. @Test public void simpleAction() { driver.get("http://www.google.com"); driver.findElement(By.name("q")) .sendKeys("Search String" + Keys.ENTER); driver.findElement(By.cssSelector("h3.r")) .click(); } Real Case
  • 11. Custom Wait while(true) { if (System.currentTimeMillis()-startTime > timeout){ throw new TimeoutException(); } try { return driver.findElement(locator); } catch (NoSuchElementException e) {} Thread.sleep(500); }
  • 13. Implicit Waits driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
  • 14. Implicit Waits driver.findElement() • Wait until element appeared in DOM • Return first element if more than one present • Throws NoSuchElementException
  • 15. Implicit Waits driver.findElements() • Wait until at least one element appeared in DOM • Return collection of all found elements • Return empty collection if no elements found
  • 16. Implicit Waits Common Issue public boolean isElementPresent(By locator) { return driver.findElements(locator).size() > 0; } if (isElementPresent(login)) driver.findElement(login).click(); if (!isElementPresent(login)) driver.findElement(logout).click();
  • 17. Implicit Waits Common Issue public boolean isElementNotPresent(By locator) { driver.manage().timeouts() .implicitlyWait(0, TimeUnit.SECONDS); boolean result= driver.findElements(locator).size() > 0; driver.manage().timeouts() .implicitlyWait(defaultTimeOut, TimeUnit.SECONDS); return result; }
  • 18. Explicit Waits WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(driver -> driver.findElement(locator)); wait.until(ExpectedConditions .presenceOfElementLocated(locator)); http://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html
  • 20. WebDriver Exceptions and RemoteWebDriver
  • 23. What if? wait = new WebDriverWait(driver,5); driver.manage().timeouts() .implicitlyWait(10, TimeUnit.SECONDS); wait.until(ExpectedConditions .presenceOfElementLocated(locator); How long will Selenium wait ? 5 15 C: 10 25
  • 24. Why? public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) { return new ExpectedCondition<WebElement>() { @Override public WebElement apply(WebDriver driver) { return findElement(locator, driver); } ... private static WebElement findElement(By by, WebDriver driver) { try { return driver.findElements(by).stream().findFirst().orElseThrow( () -> new NoSuchElementException("Cannot locate an element using " + by)); } catch (NoSuchElementException e) { throw e; } catch (WebDriverException e) { log.log(Level.WARNING, String.format("WebDriverException thrown by findElement(%s)", by), e); throw e; } }
  • 25. What if? wait = new WebDriverWait(driver,5); driver.manage().timeouts() .implicitlyWait(10, TimeUnit.SECONDS); wait.until(ExpectedConditions .presenceOfElementLocated(locator); Which exception will be thrown ? A: Timeout NoSuchElement Both None
  • 26. What if? wait = new WebDriverWait(driver,10); driver.manage().timeouts() .implicitlyWait(5, TimeUnit.SECONDS); wait.until(ExpectedConditions .presenceOfElementLocated(locator); How long will Selenium wait ? 5 15 C: 10 25
  • 27. What if? wait = new WebDriverWait(driver,11); driver.manage().timeouts() .implicitlyWait(5, TimeUnit.SECONDS); wait.until(ExpectedConditions .presenceOfElementLocated(locator); How long will Selenium wait ? 5 B: 15 11 26
  • 28. What if? wait = new WebDriverWait(driver,5); driver.manage().timeouts() .implicitlyWait(10, TimeUnit.SECONDS); wait.until(ExpectedConditions.not( ExpectedConditions.presenceOfElementLocated(locator)); How long will Selenium wait if element is present? A: 5 15 10 25
  • 29. What if? wait = new WebDriverWait(driver,5); driver.manage().timeouts() .implicitlyWait(10, TimeUnit.SECONDS); wait.until(ExpectedConditions.not( ExpectedConditions.presenceOfElementLocated(locator)); How long will Selenium wait if element is not present? C: 5 15 10 25
  • 30. Coexistence rules Use Implicit wait for element presence Do not use Explicit wait for element presence Always set implicit timeout lower than explicit Timeouts must be multiple to each other Take special care to 'not present' conditions
  • 31. Side-by-Side comparison Client Side (500ms) Can wait for anything Explicit usage TimeoutException Multiple network calls Explicit Implicit Driver Side (100ms) Element appeared in DOM Works automatically NoSuchElementException Single network call
  • 32. Few words about Selenide WebDriver Implicit Wait not used at all Custom implicit waits on client side Default polling interval - 100ms Remote WebDriver traffic issues