MCQs on Synchronization in Selenium
What is the primary purpose of synchronization in Selenium WebDriver?
a) To reduce the execution time of test cases
b) To make the script wait until the web elements are loaded and ready for interaction
c) To make the script run faster
d) To handle exceptions in the code
Answer: b) To make the script wait until the web elements are loaded and ready for interaction
Which of the following is NOT a type of synchronization in Selenium?
a) Implicit Wait
b) Explicit Wait
c) Fluent Wait
d) Static Wait
Answer: d) Static Wait
What does the Implicit Wait in Selenium do?
a) Waits for a specified amount of time for an element to be available
b) Waits for a specified condition to be true
c) Waits for an element to be removed from the DOM
d) Pauses execution for a specified time
Answer: a) Waits for a specified amount of time for an element to be available
Which method is used to set an Implicit Wait in Selenium?
a) driver.manage().timeouts().wait()
b) driver.manage().timeouts().implicitlyWait()
c) driver.manage().timeouts().explicitWait()
d) driver.manage().timeouts().fluentWait()
Answer: b) driver.manage().timeouts().implicitlyWait()
What is the difference between Implicit Wait and Explicit Wait in Selenium?
a) Implicit Wait is applied globally, Explicit Wait is applied only to specific elements
b) Implicit Wait is faster than Explicit Wait
c) Explicit Wait is applied globally, Implicit Wait is applied only to specific elements
d) There is no difference
Answer: a) Implicit Wait is applied globally, Explicit Wait is applied only to specific elements
Which class is used in Selenium to implement Explicit Wait?
a) WebDriverWait
b) FluentWait
c) ThreadWait
d) ConditionWait
Answer: a) and b
How can you specify a condition for an Explicit Wait in Selenium?
a) new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")))
b) new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("elementId")))
c) new WebDriverWait(driver, 10).until(ExpectedConditions.textToBePresentInElement(By.id("elementId"), "text"))
d) All of the above
Answer: d) All of the above
What is Fluent Wait in Selenium?
a) It is a type of Explicit Wait with a polling interval
b) It waits indefinitely for an element to be available
c) It is a combination of Implicit and Explicit Waits
d) It waits for a fixed amount of time
Answer: a) It is a type of Explicit Wait with a polling interval
Which method is used in Fluent Wait to set the frequency with which to check the condition?
a) pollingEvery()
b) withTimeout()
c) until()
d) ignoring()
Answer: a) pollingEvery()
What is the default polling frequency of Fluent Wait if not set explicitly?
a) 250 milliseconds
b) 500 milliseconds
c) 1 second
d) 5 seconds
Answer: b) 500 milliseconds
Which wait type in Selenium is most effective for handling dynamic elements that load at different times?
a) Implicit Wait
b) Explicit Wait
c) Fluent Wait
d) Static Wait
Answer: c) Fluent Wait
How does Explicit Wait differ from Fluent Wait in Selenium?
a) Explicit Wait only waits for elements to be visible, Fluent Wait can wait for any condition
b) Explicit Wait has a fixed timeout, Fluent Wait has customizable polling intervals and conditions
c) Fluent Wait is more efficient than Explicit Wait
d) There is no difference
Answer: b) Explicit Wait has a fixed timeout, Fluent Wait has customizable polling intervals and conditions
What exception does Fluent Wait ignore by default?
a) TimeoutException
b) NoSuchElementException
c) ElementNotVisibleException
d) StaleElementReferenceException
Answer: b) NoSuchElementException
Which method would you use to make Selenium wait until a specific element is visible on the page?
a) ExpectedConditions.visibilityOfElementLocated()
b) ExpectedConditions.elementToBeClickable()
c) ExpectedConditions.presenceOfElementLocated()
d) ExpectedConditions.invisibilityOfElementLocated()
Answer: a) ExpectedConditions.visibilityOfElementLocated()
What is the default timeout for Implicit Wait in Selenium if not explicitly set?
a) 0 seconds
b) 10 seconds
c) 30 seconds
d) 60 seconds
Answer: a) 0 seconds
Which wait type in Selenium is generally discouraged due to its static nature and lack of flexibility?
a) Implicit Wait
b) Explicit Wait
c) Fluent Wait
d) Thread.sleep()
Answer: d) Thread.sleep()
How would you set an Explicit Wait to wait for a maximum of 15 seconds for an element to become clickable?
a) new WebDriverWait(driver, Duration.ofSeconds(15)).until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
b) driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(15));
c) Thread.sleep(15000);
d) new WebDriverWait(driver, 15).until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
Answer: a) new WebDriverWait(driver, Duration.ofSeconds(15)).until(ExpectedConditions.elementToBeClickable(By.id("elementId")));
When should you use a Fluent Wait over an Explicit Wait?
a) When you need to wait for a condition and customize polling intervals
b) When you want to set a global wait time for all elements
c) When you want a faster wait time
d) When handling elements that are always present
Answer: a) When you need to wait for a condition and customize polling intervals
Which wait strategy in Selenium is best for handling AJAX-based elements that appear and disappear dynamically?
a) Implicit Wait
b) Explicit Wait
c) Fluent Wait
d) Static Wait
Answer: c) Fluent Wait
No comments:
Post a Comment