Consider the following Selenium Java code snippet. What will be the output if the element with id 'submitBtn' appears after 3 seconds?
WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); long start = System.currentTimeMillis(); driver.findElement(By.id("submitBtn")); long end = System.currentTimeMillis(); System.out.println("Waited for: " + (end - start) + " ms");
Implicit wait tells Selenium how long to keep trying to find an element before throwing an exception.
The implicit wait is set to 5 seconds, but since the element appears after 3 seconds, Selenium waits about 3 seconds before finding it. So the printed wait time is approximately 3000 ms.
You want to check if the implicit wait timeout is set to 10 seconds in Selenium Java. Which assertion is correct?
Check the method to get implicit wait timeout and compare durations properly.
Option D correctly compares the implicit wait timeout in seconds using getImplicitWaitTimeout() and toSeconds(). Option D is invalid because getImplicitWaitTimeout() returns a Duration, but assertEquals expects exact object equality which may fail. Option D uses a non-existent method. Option D compares Duration.ofMillis(10000) which is correct duration but the method call is invalid.
Given this code snippet, the test fails with NoSuchElementException immediately. Why?
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); driver.findElement(By.xpath("//div[@class='dynamic']"));
Implicit wait retries finding the element until timeout or element found.
If the element locator is wrong or the element never appears, implicit wait will retry until timeout but eventually throw NoSuchElementException. It does not fail immediately unless timeout is zero.
Which of the following is a known limitation of using implicit wait in Selenium?
Think about how implicit wait affects all element searches and interacts with explicit waits.
Implicit wait applies globally to all findElement calls and can cause unexpected delays or conflicts when used with explicit waits. It does not discriminate element types, does not retry assertions, and can be changed anytime.
You want to use both implicit and explicit waits in your Selenium Java tests. Which approach is best to avoid timing issues?
Implicit and explicit waits can interfere if both are set with non-zero values.
Best practice is to set implicit wait to zero when using explicit waits to avoid unexpected delays and conflicts. Using explicit waits only where needed gives precise control.