1. What is Selenium? What are its components?
👉 Selenium is an open-source automation tool for web applications.
Components:
-
Selenium IDE – record & playback
-
Selenium WebDriver – automation with multiple browsers
-
Selenium Grid – run tests in parallel/distributed
2. Difference between Selenium 2 (WebDriver) and Selenium 3/4.
👉 Selenium 2 introduced WebDriver.
👉 Selenium 3/4 improved architecture, added W3C compliance, relative locators, Chrome DevTools integration.
3. What are different types of locators in Selenium?
👉 ID, Name, ClassName, TagName, LinkText, PartialLinkText, CSS Selector, XPath
4. Difference between findElement()
and findElements()
.
👉 findElement()
→ returns first matching element (throws exception if not found).
👉 findElements()
→ returns a list of matching elements (empty list if not found).
5. Difference between driver.close()
and driver.quit()
.
👉 close()
→ closes current browser window.
👉 quit()
→ closes all browser windows & ends session.
6. How do you handle dynamic web elements in Selenium?
👉 Use dynamic XPath, CSS with contains/starts-with, or by using unique attributes.
7. What is an XPath? Difference between Absolute and Relative XPath.
👉 XPath is used to locate elements in XML/HTML.
-
Absolute XPath → starts from root (
/html/body/...
) -
Relative XPath → starts from anywhere (
//div[@id='test']
)
8. What are the different waits in Selenium?
👉 Implicit Wait – waits globally for elements.
👉 Explicit Wait – waits for a specific condition.
👉 Fluent Wait – waits with polling frequency & exception handling.
9. How to handle dropdowns in Selenium?
👉 Use Select class:
Select s = new Select(driver.findElement(By.id("dropdown"))); s.selectByVisibleText("Option1");
10. How do you handle multiple windows in Selenium?
👉 Use getWindowHandles()
and switch with driver.switchTo().window(handle)
.
🔹 Intermediate Selenium Q&A
11. How do you handle alerts and popups in Selenium?
👉 Use driver.switchTo().alert()
→ accept()
, dismiss()
, getText()
, sendKeys()
.
12. How to perform mouse hover, right-click, and drag-and-drop?
👉 Use Actions class:
Actions a = new Actions(driver); a.moveToElement(element).perform(); // hover a.contextClick(element).perform(); // right-click a.dragAndDrop(src, dest).perform(); // drag-drop
13. How do you capture screenshots in Selenium?
👉 Use TakesScreenshot
:
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
14. Difference between WebDriver and WebElement.
👉 WebDriver → Interface for browser automation.
👉 WebElement → Represents elements inside the page.
15. How to handle frames/iframes in Selenium?
👉 Use driver.switchTo().frame(index/name/WebElement)
👉 Switch back: driver.switchTo().defaultContent()
16. What is Page Object Model (POM)? Why is it used?
👉 POM is a design pattern where each page has a separate class.
👉 Improves readability, reusability, and maintainability of test scripts.
17. Difference between getText()
and getAttribute()
.
👉 getText()
→ Gets visible text.
👉 getAttribute("value")
→ Gets attribute/property value.
18. How do you handle synchronization issues?
👉 Use explicit waits with ExpectedConditions instead of Thread.sleep().
🔹 Advanced Selenium Q&A
19. What is Selenium Grid? How do you run tests in parallel?
👉 Selenium Grid allows distributed test execution across different browsers, OS, and machines.
👉 Parallel tests can be executed using TestNG parallel execution with Grid.
20. How do you integrate Selenium with TestNG/Maven/Jenkins?
👉 TestNG → test framework (annotations, assertions, reports).
👉 Maven → project management & dependency tool.
👉 Jenkins → CI/CD tool to trigger Selenium scripts automatically.