Selenium Testing Framework Technology & Digital Applications 3 — Questions and Answers
Question 1: Which Selenium class provides built-in support for handling dropdown menus created with the <select> HTML tag?
- Select (Correct answer)
- Dropdown
- ComboBox
- OptionList
Correct answer: Select
The Select class in Selenium wraps a WebElement pointing to a <select> tag and provides methods like selectByVisibleText() and selectByIndex().
Question 2: What exception is thrown by Selenium when an element is found but cannot be interacted with because it is not visible?
- ElementNotInteractableException (Correct answer)
- NoSuchElementException
- StaleElementReferenceException
- InvalidSelectorException
Correct answer: ElementNotInteractableException
ElementNotInteractableException is raised when WebDriver locates an element but it is hidden or disabled, preventing user interactions.
Question 3: In Selenium, how do you upload a file using an <input type='file'> element?
- Call sendKeys() with the absolute file path on the element (Correct answer)
- Use driver.uploadFile() with the element locator
- Click the element and use AutoIT to handle the OS dialog
- Use Actions.dragAndDrop() to drop the file
Correct answer: Call sendKeys() with the absolute file path on the element
For native file input elements, sendKeys() with the file's absolute path populates the field without opening the OS dialog.
Question 4: What does the Selenium method driver.getPageSource() return?
- The complete HTML source of the current page as a string (Correct answer)
- The DOM tree as a JSON object
- Only the visible text content of the page
- The HTTP response headers of the page
Correct answer: The complete HTML source of the current page as a string
getPageSource() returns the full HTML markup of the current page, useful for assertions against rendered content.
Question 5: Which strategy should you prefer for locating elements to maximize test stability in Selenium?
- Unique ID attributes set specifically for testing (Correct answer)
- Absolute XPath from the root
- Element position (nth-child index)
- Link text that may change with locale
Correct answer: Unique ID attributes set specifically for testing
Test-specific IDs are stable, unique, and not affected by UI restructuring or text changes, making them the most resilient locator strategy.
Question 6: What is a 'StaleElementReferenceException' in Selenium and when does it occur?
- When a previously located element no longer exists in the DOM due to a page update (Correct answer)
- When two tests try to access the same element simultaneously
- When an element is located outside the viewport
- When the WebDriver version mismatches the browser version
Correct answer: When a previously located element no longer exists in the DOM due to a page update
StaleElementReferenceException occurs when the DOM is refreshed or modified after the element reference was captured, invalidating it.
Question 7: Which Selenium component allows running the same tests across different browsers and operating systems in parallel?
- Selenium Grid (Correct answer)
- Selenium IDE
- Selenium RC
- Selenium WebDriver standalone
Correct answer: Selenium Grid
Selenium Grid distributes test execution across multiple machines and browser configurations, enabling parallel cross-browser testing.
Which Selenium class provides built-in support for handling dropdown menus created with the HTML tag?