Selenium Testing Framework Technology & Digital Applications 2 — Questions and Answers
Question 1: Which Selenium WebDriver method is used to switch control to a newly opened browser window or tab?
- driver.switchTo().window(handle) (Correct answer)
- driver.switchWindow(handle)
- driver.focusWindow(handle)
- driver.changeTab(handle)
Correct answer: driver.switchTo().window(handle)
driver.switchTo().window(handle) switches WebDriver focus to the specified window handle.
Question 2: What does the Page Object Model (POM) design pattern primarily achieve in Selenium test suites?
- Separates test logic from UI element locators and interactions (Correct answer)
- Speeds up browser startup time
- Automatically retries failed tests
- Generates HTML test reports
Correct answer: Separates test logic from UI element locators and interactions
POM separates UI interaction code into dedicated page classes, making tests easier to maintain when the UI changes.
Question 3: Which CSS selector correctly targets an input element with the attribute type='email'?
- input[type='email'] (Correct answer)
- input#email
- input.email
- input:email
Correct answer: input[type='email']
Attribute selectors use square bracket syntax, so input[type='email'] matches input elements with that specific attribute value.
Question 4: In Selenium Grid, what is the role of the 'Hub'?
- It receives test commands and routes them to available nodes (Correct answer)
- It executes the browser sessions directly
- It stores test results in a database
- It generates WebDriver bindings for each browser
Correct answer: It receives test commands and routes them to available nodes
The Hub acts as a central server that receives WebDriver requests and delegates them to registered nodes that run the actual browsers.
Question 5: Which JavaScript executor call in Selenium scrolls the page to the bottom?
- js.executeScript('window.scrollTo(0, document.body.scrollHeight)') (Correct answer)
- js.executeScript('page.scrollBottom()')
- js.executeScript('scroll.toEnd()')
- js.executeScript('document.scroll("bottom")')
Correct answer: js.executeScript('window.scrollTo(0, document.body.scrollHeight)')
window.scrollTo(0, document.body.scrollHeight) scrolls to the full height of the page, effectively reaching the bottom.
Question 6: What is the purpose of driver.manage().timeouts().implicitlyWait() in Selenium?
- It tells WebDriver to poll the DOM for a set duration when locating elements (Correct answer)
- It pauses test execution for a fixed number of seconds
- It sets the maximum time for a page to fully load
- It waits only for AJAX calls to complete
Correct answer: It tells WebDriver to poll the DOM for a set duration when locating elements
implicitlyWait instructs WebDriver to retry element lookups for the specified duration before throwing NoSuchElementException.
Question 7: When using XPath, what does the double slash '//' at the start of an expression signify?
- Search for the element anywhere in the entire document (Correct answer)
- Search only direct children of the root
- Search within the current node's siblings
- Search within commented-out HTML nodes
Correct answer: Search for the element anywhere in the entire document
A leading '//' in XPath means the search traverses the entire document tree, not just direct children.
Which Selenium WebDriver method is used to switch control to a newly opened browser window or tab?