Selenium Testing Framework Technology & Digital Applications 5 — Questions and Answers
Question 1: What is the primary advantage of using Explicit Waits over Implicit Waits in Selenium?
- Explicit waits apply conditions to specific elements, preventing unnecessary delays (Correct answer)
- Explicit waits are faster to write
- Explicit waits work globally across all element lookups
- Explicit waits never timeout
Correct answer: Explicit waits apply conditions to specific elements, preventing unnecessary delays
Explicit waits use ExpectedConditions targeting specific elements, so the test proceeds as soon as the condition is met rather than sleeping for a fixed duration.
Question 2: Which ExpectedCondition in Selenium waits until an element is visible AND enabled so that you can click it?
- elementToBeClickable(locator) (Correct answer)
- visibilityOfElementLocated(locator)
- presenceOfElementLocated(locator)
- elementToBeSelected(locator)
Correct answer: elementToBeClickable(locator)
elementToBeClickable waits until the element is visible in the DOM and enabled, ensuring a click interaction will succeed.
Question 3: In Selenium, how do you execute a JavaScript script that returns a value back to the test?
- Cast the result of executeScript() to the expected type after using a 'return' statement in the script (Correct answer)
- Use driver.getScriptResult() after calling executeScript()
- Assign the value to window.__result and read it with getAttribute()
- JavaScript return values are not accessible from Selenium
Correct answer: Cast the result of executeScript() to the expected type after using a 'return' statement in the script
executeScript() returns a Java Object when the JS script contains a 'return' statement, which you then cast to the expected type.
Question 4: What Selenium API would you use to simulate hovering over an element to reveal a dropdown menu?
- new Actions(driver).moveToElement(element).perform() (Correct answer)
- driver.hover(element)
- element.triggerEvent('mouseover')
- driver.switchTo().frame(element)
Correct answer: new Actions(driver).moveToElement(element).perform()
The Actions class moveToElement() method dispatches a mouseover event, which is necessary to reveal CSS :hover-triggered elements.
Question 5: When writing a Selenium test that interacts with an iframe, what must you do before accessing elements inside it?
- Switch to the iframe using driver.switchTo().frame() (Correct answer)
- Use a relative XPath prefixed with //iframe//
- Set driver.setCurrentFrame(iframeId)
- No special handling is needed; WebDriver searches all frames automatically
Correct answer: Switch to the iframe using driver.switchTo().frame()
WebDriver operates in a single frame context at a time; you must switch into the iframe before locating its child elements.
Question 6: Which tool is commonly integrated with Selenium to generate detailed HTML test execution reports with screenshots?
- ExtentReports (Correct answer)
- Postman
- SoapUI
- JMeter
Correct answer: ExtentReports
ExtentReports is a popular reporting library that integrates with Selenium test frameworks to produce rich HTML reports including screenshots on failure.
Question 7: In a data-driven Selenium test using TestNG, which annotation and attribute enable running the same test method with multiple data sets?
- @Test(dataProvider='providerName') with a @DataProvider method (Correct answer)
- @Test(dataset='csvFile') referencing a CSV
- @Parameterized with a static data() method
- @RunWith(Parameterized.class) from JUnit
Correct answer: @Test(dataProvider='providerName') with a @DataProvider method
@DataProvider supplies multiple argument arrays to a @Test method annotated with dataProvider='name', running the test once per data set.
What is the primary advantage of using Explicit Waits over Implicit Waits in Selenium?