Selenium WebDriver Technology & Digital Applications 3 — Questions and Answers
Question 1: In Selenium WebDriver, what is the purpose of the WebDriverWait class?
- To wait for a specific condition before proceeding with the next step (Correct answer)
- To pause test execution for a fixed number of seconds
- To wait until the page title changes
- To set the implicit wait globally for all elements
Correct answer: To wait for a specific condition before proceeding with the next step
WebDriverWait implements explicit waits, polling at intervals until a specified ExpectedCondition is met or the timeout expires.
Question 2: What does the CSS selector 'input[type="submit"]' target in Selenium?
- All input elements with type attribute equal to submit (Correct answer)
- All submit buttons including <button> tags
- The first input element on the page
- An input element with the class name 'submit'
Correct answer: All input elements with type attribute equal to submit
The CSS selector input[type='submit'] matches any <input> element whose type attribute is exactly 'submit'.
Question 3: Which HTTP status code does Selenium Grid Hub return when a requested browser capability is unavailable?
- Selenium throws a SessionNotCreatedException, not a direct HTTP status (Correct answer)
- 404 Not Found
- 503 Service Unavailable
- 400 Bad Request
Correct answer: Selenium throws a SessionNotCreatedException, not a direct HTTP status
When no node on the Grid can fulfill the requested capabilities, Selenium throws a SessionNotCreatedException rather than exposing a raw HTTP status to the test code.
Question 4: What is the correct way to handle a browser alert dialog that asks for user input in Selenium?
- driver.switchTo().alert().sendKeys('input') then .accept() (Correct answer)
- driver.findElement(By.id('alert')).sendKeys('input')
- driver.switchTo().alert().setText('input')
- driver.alert().type('input')
Correct answer: driver.switchTo().alert().sendKeys('input') then .accept()
After switching to the alert, sendKeys() types the desired input and accept() confirms the prompt dialog.
Question 5: What is the difference between driver.close() and driver.quit() in Selenium WebDriver?
- close() closes only the current window; quit() closes all windows and ends the session (Correct answer)
- close() ends the entire session; quit() closes only the current window
- They are identical in behavior
- close() kills the browser process; quit() sends a graceful shutdown signal
Correct answer: close() closes only the current window; quit() closes all windows and ends the session
driver.close() closes only the currently focused browser window, while driver.quit() terminates the entire WebDriver session and closes all associated windows.
Question 6: Which Selenium locator strategy uses an XML path expression to find elements?
- By.xpath() (Correct answer)
- By.cssSelector()
- By.id()
- By.linkText()
Correct answer: By.xpath()
By.xpath() uses XPath expressions to navigate the DOM tree and locate elements based on their attributes, hierarchy, or text content.
Question 7: In Selenium WebDriver, what does JavascriptExecutor allow testers to do?
- Execute arbitrary JavaScript code in the browser context (Correct answer)
- Intercept browser network requests
- Inject CSS styles into the page
- Access browser cookies directly
Correct answer: Execute arbitrary JavaScript code in the browser context
JavascriptExecutor provides the executeScript() and executeAsyncScript() methods to run JavaScript directly in the browser from your test code.
In Selenium WebDriver, what is the purpose of the WebDriverWait class?