MCQs on WebDriverWait and Synchronization | Selenium

Understand the essentials of synchronization in Selenium, including implicit vs. explicit waits, fluent waits, ExpectedConditions, and handling timeouts effectively for reliable and robust web test automation.


MCQs on WebDriverWait and Synchronization in Selenium

1. Implicit vs. Explicit Wait

  1. What is the primary purpose of using waits in Selenium?
    a) To slow down the test execution
    b) To synchronize the script with dynamic elements
    c) To improve browser performance
    d) To generate test reports
  2. Which Selenium wait type applies a global timeout for all elements?
    a) Explicit wait
    b) Implicit wait
    c) Fluent wait
    d) WebDriverWait
  3. How do you set an implicit wait in Selenium?
    a) driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
    b) driver.wait(10);
    c) driver.manage().implicitTimeout(10);
    d) driver.setTimeout(10);
  4. What happens if an element is not found within the implicit wait time?
    a) Selenium throws an exception immediately
    b) Selenium retries until the timeout is reached
    c) Selenium skips the test case
    d) Selenium executes the next command
  5. When would you prefer explicit wait over implicit wait?
    a) When handling all elements in the DOM
    b) When dealing with a specific condition for an element
    c) When testing only static web pages
    d) When no dynamic content is present
  6. Which of the following is used to define an explicit wait in Selenium?
    a) FluentWait
    b) Thread.sleep()
    c) WebDriverWait
    d) WaitDriver
  7. How do you configure explicit wait for a button to be clickable?
    a) WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(button));
    b) driver.explicitWait(10).click(button);
    c) driver.untilElementClickable(button, 10);
    d) button.waitForClickability(10);
  8. Which command cancels an implicit wait in Selenium?
    a) driver.manage().timeouts().implicitlyWait(Duration.ZERO);
    b) driver.removeImplicitWait();
    c) driver.manage().timeouts().disable();
    d) driver.resetWaits();
  9. How does implicit wait affect explicit waits in the same test?
    a) It overrides explicit waits
    b) Both waits are combined
    c) They work independently
    d) Implicit wait cancels explicit wait
  10. What is one major drawback of using implicit wait?
    a) It can lead to longer execution times
    b) It is only applicable to buttons
    c) It cannot handle stale element exceptions
    d) It is no longer supported by Selenium

2. FluentWait and ExpectedConditions

  1. What is FluentWait primarily used for?
    a) Waiting for an element to disappear
    b) Defining a custom polling interval and conditions
    c) Handling browser timeouts
    d) Managing static waits
  2. Which of these is a key feature of FluentWait?
    a) It throws an exception immediately if the condition is not met
    b) It polls at specified intervals before throwing an exception
    c) It works only with buttons and links
    d) It disables implicit waits
  3. How do you define a FluentWait with a polling interval?
    a) new FluentWait(driver).withTimeout(10).pollingEvery(1);
    b) new FluentWait(driver).withTimeout(Duration.ofSeconds(10)).pollingEvery(Duration.ofSeconds(1));
    c) driver.waitFluently(10, 1);
    d) driver.FluentWait(10, 1);
  4. What does the withMessage() method in FluentWait do?
    a) Sets a log message for successful waits
    b) Displays a custom exception message if the wait fails
    c) Defines the polling interval
    d) Automatically retries failed actions
  5. Which ExpectedConditions is used to wait for an alert to appear?
    a) ExpectedConditions.alertPresent()
    b) ExpectedConditions.alertIsPresent()
    c) ExpectedConditions.isAlertPresent()
    d) ExpectedConditions.waitForAlert()
  6. How do you handle a stale element reference exception using FluentWait?
    a) Catch the exception and retry immediately
    b) Configure retry logic in until() with a polling interval
    c) Use implicit wait to handle it automatically
    d) Selenium does not support stale element handling
  7. Which of these is an example of a valid ExpectedCondition?
    a) ExpectedConditions.elementToBeVisible(element);
    b) ExpectedConditions.waitUntilLoaded(element);
    c) ExpectedConditions.isElementPresent(element);
    d) ExpectedConditions.waitForElement(element);
  8. How does FluentWait improve upon WebDriverWait?
    a) It is faster than WebDriverWait
    b) It provides custom polling intervals and exception handling
    c) It replaces implicit waits
    d) It is used only for alerts
  9. Which of the following is an invalid ExpectedConditions method?
    a) textToBePresentInElementLocated()
    b) elementToBeSelected()
    c) visibilityOfElementLocated()
    d) navigateToFrame()
  10. What happens if FluentWait does not find the element within the timeout?
    a) The test fails immediately
    b) It throws a TimeoutException
    c) It retries indefinitely
    d) It cancels the test run

3. Handling Timeouts

  1. What is a timeout exception in Selenium?
    a) An error when the script is paused manually
    b) An error when a wait condition is not met in time
    c) An error when the browser crashes
    d) An error when the WebDriver fails to start
  2. How do you handle timeout exceptions in a Selenium script?
    a) Use a try-catch block and implement alternative logic
    b) Increase the system timeout settings
    c) Restart the browser
    d) Use Thread.sleep() instead of waits
  3. Which method sets the page load timeout in Selenium?
    a) driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
    b) driver.pageLoadTimeout(10);
    c) driver.waitForPageLoad(10);
    d) driver.setLoadTimeout(10);
  4. What happens when a page load timeout is exceeded?
    a) The page continues to load, but the script moves on
    b) Selenium throws a TimeoutException
    c) The browser closes automatically
    d) Selenium retries the page load
  5. How do you set a script timeout in Selenium?
    a) driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(10));
    b) driver.scriptTimeout(10);
    c) driver.manage().timeouts().setScriptTimeout(10);
    d) driver.setTimeout(Duration.ofSeconds(10));
  6. Which timeout is used for asynchronous JavaScript execution?
    a) Page load timeout
    b) Implicit wait
    c) Script timeout
    d) Explicit wait
  7. What is the default timeout for WebDriverWait?
    a) 5 seconds
    b) 10 seconds
    c) 15 seconds
    d) 20 seconds
  8. How do you ensure the browser waits for AJAX calls to complete?
    a) Use explicit wait with ExpectedConditions.invisibilityOfElementLocated()
    b) Configure FluentWait with a polling interval
    c) Use driver.executeScript("return jQuery.active == 0");
    d) All of the above
  9. Which exception occurs when a page takes longer than the specified timeout to load?
    a) TimeoutException
    b) NoSuchElementException
    c) StaleElementReferenceException
    d) ElementNotInteractableException
  10. Why should you avoid overusing Thread.sleep() in Selenium?
    a) It reduces script readability
    b) It adds unnecessary delays to execution
    c) It doesn’t handle dynamic waits effectively
    d) All of the above

Here are the answers again:

QnoAnswer
1b) To synchronize the script with dynamic elements
2b) Implicit wait
3a) driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
4b) Selenium retries until the timeout is reached
5b) When dealing with a specific condition for an element
6c) WebDriverWait
7a) WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(button));
8a) driver.manage().timeouts().implicitlyWait(Duration.ZERO);
9c) They work independently
10a) It can lead to longer execution times
11b) Defining a custom polling interval and conditions
12b) It polls at specified intervals before throwing an exception
13b) new FluentWait(driver).withTimeout(Duration.ofSeconds(10)).pollingEvery(Duration.ofSeconds(1));
14b) Displays a custom exception message if the wait fails
15b) ExpectedConditions.alertIsPresent()
16b) Configure retry logic in until() with a polling interval
17a) ExpectedConditions.elementToBeVisible(element);
18b) It provides custom polling intervals and exception handling
19d) ExpectedConditions.waitForElement(element);
20b) It throws a TimeoutException
21b) An error when a wait condition is not met in time
22a) Use a try-catch block and implement alternative logic
23a) driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
24b) Selenium throws a TimeoutException
25a) driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(10));
26c) Script timeout
27b) 10 seconds
28d) All of the above
29a) TimeoutException
30d) All of the above

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top