Automation Testing Selenium WebDriver 1 — Questions and Answers
Question 1: Which Selenium WebDriver method is used to navigate to a URL?
- driver.get(url) (Correct answer)
- driver.open(url)
- driver.navigate(url)
- driver.load(url)
Correct answer: driver.get(url)
driver.get(url) loads a new web page in the current browser window in Selenium WebDriver.
Question 2: What is the purpose of WebDriverWait in Selenium?
- To pause execution until an expected condition is met (Correct answer)
- To slow down the browser
- To capture screenshots
- To scroll the page
Correct answer: To pause execution until an expected condition is met
WebDriverWait implements explicit waits, polling until a specified condition (like element visibility) is true before a timeout.
Question 3: Which locator strategy is generally considered most reliable in Selenium for uniquely identifying elements?
- ID (Correct answer)
- XPath
- Class name
- Tag name
Correct answer: ID
ID locators are fastest and most reliable because IDs should be unique within a page per HTML specification.
Question 4: What does driver.findElements() return when no matching elements are found?
- An empty list (Correct answer)
- null
- NoSuchElementException
- An empty WebElement
Correct answer: An empty list
findElements() returns an empty list when no matching elements exist, unlike findElement() which throws NoSuchElementException.
Question 5: Which Selenium method is used to switch to an iframe?
- driver.switchTo().frame() (Correct answer)
- driver.switchTo().window()
- driver.navigate().to()
- driver.manage().frame()
Correct answer: driver.switchTo().frame()
driver.switchTo().frame() switches the WebDriver context into an iframe so its elements can be interacted with.
Question 6: What is the difference between driver.close() and driver.quit() in Selenium?
- close() closes the current window; quit() closes all windows and ends the session (Correct answer)
- They are identical
- quit() closes one tab; close() ends the session
- close() is deprecated
Correct answer: close() closes the current window; quit() closes all windows and ends the session
driver.close() closes only the active browser window while driver.quit() terminates the entire WebDriver session and all associated windows.
Which Selenium WebDriver method is used to navigate to a URL?