Selenium WebDriver Advanced Techniques & Frameworks 1 β Questions and Answers
Question 1: What is the Page Object Model (POM) design pattern in Selenium?
- A pattern that models each web page as a class with its elements and actions (Correct answer)
- A pattern for organizing test data in spreadsheets
- A design pattern for parallel test execution
- A Selenium built-in reporting framework
Correct answer: A pattern that models each web page as a class with its elements and actions
POM encapsulates page elements and interactions inside dedicated classes, separating test logic from UI details.
Question 2: Which WebDriverWait method polls until a condition is true or a timeout is reached?
- wait.until(ExpectedConditions.condition) (Correct answer)
- wait.waitFor(condition)
- wait.pause(condition)
- wait.expect(condition)
Correct answer: wait.until(ExpectedConditions.condition)
WebDriverWait.until() repeatedly evaluates the ExpectedCondition until it returns a truthy value or the timeout expires.
Question 3: What does ExpectedConditions.visibilityOfElementLocated() wait for?
- The element to be present in the DOM and visible (Correct answer)
- The element to be clickable
- The element to have non-empty text
- The page to fully load
Correct answer: The element to be present in the DOM and visible
visibilityOfElementLocated() waits until the element is present in the DOM and its size is greater than zero.
Question 4: How do you execute JavaScript in the browser using WebDriver?
- ((JavascriptExecutor) driver).executeScript('script') (Correct answer)
- driver.runScript('script')
- driver.execute('script')
- driver.js('script')
Correct answer: ((JavascriptExecutor) driver).executeScript('script')
Cast the driver to JavascriptExecutor and call executeScript() to run arbitrary JS in the current page context.
Question 5: What is the Actions class used for in Selenium WebDriver?
- Performing complex user gestures like drag-and-drop, hover, and multi-key press (Correct answer)
- Creating custom test assertions
- Managing browser cookies
- Taking element screenshots
Correct answer: Performing complex user gestures like drag-and-drop, hover, and multi-key press
The Actions class builds chains of keyboard and mouse interactions for advanced user simulation.
Question 6: Which method in the Actions class simulates hovering the mouse over an element?
- actions.moveToElement(element) (Correct answer)
- actions.hover(element)
- actions.mouseOver(element)
- actions.focus(element)
Correct answer: actions.moveToElement(element)
moveToElement() moves the virtual mouse pointer to the center of the target element to trigger hover states.
What is the Page Object Model (POM) design pattern in Selenium?