Selenium WebDriver Technology & Digital Applications 2 β Questions and Answers
Question 1: Which Selenium WebDriver method is used to switch the driver's context to an iframe?
- driver.switchTo().frame() (Correct answer)
- driver.switchTo().window()
- driver.switchTo().alert()
- driver.switchTo().defaultContent()
Correct answer: driver.switchTo().frame()
driver.switchTo().frame() switches the WebDriver context into the specified iframe so you can interact with its elements.
Question 2: What does the WebDriver method driver.getWindowHandles() return?
- A Set of all open browser window/tab handles (Correct answer)
- The title of the current window
- The URL of the active window
- A List of all open browser window/tab handles
Correct answer: A Set of all open browser window/tab handles
driver.getWindowHandles() returns a Set<String> containing the handles of all currently open browser windows or tabs.
Question 3: Which class in Selenium WebDriver is used to simulate keyboard and mouse actions like hover, drag-and-drop, and right-click?
- Actions (Correct answer)
- Robot
- Keys
- EventFiringWebDriver
Correct answer: Actions
The Actions class provides an API for building complex user interaction sequences such as hover, drag-and-drop, and context clicks.
Question 4: What is the role of DesiredCapabilities in Selenium WebDriver?
- To specify browser properties and settings before launching a session (Correct answer)
- To store test results after a session
- To define locator strategies for finding elements
- To configure wait timeouts for elements
Correct answer: To specify browser properties and settings before launching a session
DesiredCapabilities allows testers to configure browser type, version, platform, and other settings before starting a WebDriver session.
Question 5: Which Selenium component acts as a proxy, translating WebDriver commands into browser-specific instructions?
- Browser driver (e.g., ChromeDriver, GeckoDriver) (Correct answer)
- Selenium Grid Hub
- Selenium IDE
- TestNG framework
Correct answer: Browser driver (e.g., ChromeDriver, GeckoDriver)
Browser-specific drivers like ChromeDriver and GeckoDriver translate the WebDriver protocol commands into native browser automation calls.
Question 6: What does driver.manage().window().maximize() do in Selenium WebDriver?
- Maximizes the browser window to fill the screen (Correct answer)
- Opens a new browser window
- Sets the window to full-screen mode
- Resizes the window to 1920x1080
Correct answer: Maximizes the browser window to fill the screen
driver.manage().window().maximize() enlarges the browser window to the maximum size available on the current display.
Question 7: Which assertion type in TestNG would cause the test suite to immediately stop execution upon failure?
- Assert (hard assertion) (Correct answer)
- SoftAssert
- VerifyAssert
- LazyAssert
Correct answer: Assert (hard assertion)
Hard assertions using Assert class stop test execution immediately when the condition fails, unlike SoftAssert which collects failures and reports them at the end.
Which Selenium WebDriver method is used to switch the driver's context to an iframe?