Selenium WebDriver Advanced Techniques & Frameworks 2 β Questions and Answers
Question 1: Which interface must a driver implement to support taking screenshots?
- TakesScreenshot (Correct answer)
- ScreenCapture
- ScreenshotCapable
- CaptureScreen
Correct answer: TakesScreenshot
Cast the driver to TakesScreenshot and call getScreenshotAs() to capture the current browser state as an image.
Question 2: What file format does getScreenshotAs(OutputType.FILE) return?
- A temporary PNG file (Correct answer)
- A JPEG file
- A Base64 string saved to disk
- A BMP file
Correct answer: A temporary PNG file
OutputType.FILE returns a temporary File object containing the screenshot in PNG format.
Question 3: What is a FluentWait in Selenium WebDriver?
- A configurable wait that can ignore specific exceptions and set polling frequency (Correct answer)
- A wait that uses CSS animations to detect readiness
- A replacement for Thread.sleep with better performance
- A wait that polls the DOM every second by default
Correct answer: A configurable wait that can ignore specific exceptions and set polling frequency
FluentWait allows setting custom polling intervals, timeout durations, and exceptions to ignore during waiting.
Question 4: How do you handle a file upload dialog in Selenium WebDriver?
- Send the file path via sendKeys() to the file input element (Correct answer)
- Use Actions to click Browse and type the path
- Call driver.uploadFile(path)
- Use JavascriptExecutor to set input value
Correct answer: Send the file path via sendKeys() to the file input element
File input elements accept sendKeys() with the absolute file path, bypassing the OS file dialog entirely.
Question 5: Which Selenium component is used to run tests in parallel across multiple browsers?
- Selenium Grid (Correct answer)
- Selenium Hub
- Selenium Parallel
- Selenium Farm
Correct answer: Selenium Grid
Selenium Grid distributes test execution across multiple machines or browsers simultaneously via a hub-node architecture.
Question 6: What does the @FindBy annotation do in Page Object Model?
- Lazy-initializes a WebElement using the specified locator strategy (Correct answer)
- Immediately finds and caches the element at page load
- Marks a test method for element injection
- Creates a list of all matching elements
Correct answer: Lazy-initializes a WebElement using the specified locator strategy
@FindBy with PageFactory.initElements() creates a proxy WebElement that is located only when first accessed.
Which interface must a driver implement to support taking screenshots?