Hi all,
The following is the Selenium Interview question along with its answer. If you are interested in finding out our complete list of Selenium Interview questions, you can refer to http://www.qafox.com/selenium-interview-questions/
Question: What is the difference between Implicit Wait and Explicit Wait?
Answer: The following is the answer to this question:
Explicit Wait will make the WebDriver wait for a specific web element for the specified time. i.e. Using Explicit Wait, we can make the WebDriver wait for a specific web element say ‘a’ for 5 seconds and another web element say ‘b’ for 10 seconds.
Whereas Implicit Wait will make the WebDriver wait for all web elements for the same specified time. Its generally not set for one or two web elements, instead it is globally set once will be applicable for all elements. i.e., Unlike Explicit Wait, Implicit Wait once set will be applicable to all the web elements and hence the specified wait time will be applicable for all the web elements.
Example for Implicit Wait: The following is an example for Implicit Wait which waits for all the web elements say Dropbutton button and Facebook link for 5 seconds.
public class Demo { public static void main(String args[]) throws InterruptedException { WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("http://www.omayo.blogspot.com"); driver.manage().window().maximize(); driver.findElement(By.className("dropbtn")).click(); driver.findElement(By.linkText("Facebook")).click(); } }
Example for Explicit Wait: The following is an example for Explicit Wait which specifically waits for a specific element say Dropdown button for 5 seconds.
public class Demo { public static void main(String args[]) throws InterruptedException { WebDriver driver = new FirefoxDriver(); WebDriverWait wait = new WebDriverWait(driver, 5); driver.get("http://www.omayo.blogspot.com"); driver.manage().window().maximize(); driver.findElement(By.className("dropbtn")).click(); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Facebook"))); element.click(); } }
If you are interested in finding out our complete list of Selenium Interview questions, you can refer to http://www.qafox.com/selenium-interview-questions/
Please leave your questions/comments/feedback below.
Happy Learning 🙂
Arun Motoori (www.QAFox.com)
Thanks Arun, for excellent post . Simple explanation understood the difference between the waits. Keep up the good work.
You are most welcome 🙂