What is Selenium? Easy
Selenium is an open-source automation testing tool used to automate web browsers. It allows testers and developers to simulate user interactions like clicking buttons, filling forms, navigating pages, and validating results.
Selenium supports multiple programming languages such as Java, Python, C#, and JavaScript. It works with major browsers like Chrome, Firefox, Edge, and Safari.
What are the components of Selenium? Easy
Selenium consists of four major components:
In real projects, WebDriver and Grid are most commonly used.
What is Selenium WebDriver? Easy
WebDriver is the main component of Selenium used to automate browser actions. It directly communicates with the browser using browser-specific drivers like ChromeDriver or GeckoDriver.
Unlike Selenium RC, WebDriver does not use JavaScript injection. It communicates using browser-native automation support.
What is a locator in Selenium? Easy
A locator is a way to identify web elements on a page. Selenium provides multiple locator strategies:
Choosing the right locator improves stability of automation scripts.
Difference between CSS Selector and XPath? Easy
CSS Selector is generally faster and simpler for basic element selection.
XPath is more powerful and allows navigating up and down the DOM tree.
In interviews, mention that CSS cannot move backward in DOM while XPath can.
How do you launch a browser in Selenium? Easy
To launch Chrome browser in Java:
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");
Before launching, the appropriate browser driver must be configured.
What is the difference between driver.close() and driver.quit()? Easy
close() closes only the current browser window.
quit() closes all browser windows and ends the WebDriver session.
quit() is recommended in test frameworks.
What is implicit wait? Easy
Implicit wait tells Selenium to wait for a specified time before throwing NoSuchElementException.
It applies globally to all elements.
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
What is explicit wait? Easy
Explicit wait waits for a specific condition before proceeding.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login")));
Explicit wait is more reliable than implicit wait.
What is Page Object Model (POM)? Easy
POM is a design pattern in Selenium where each webpage is represented as a class.
This improves maintainability, readability, and reusability of test scripts.
How do you handle dropdowns in Selenium? Medium
Dropdowns can be handled using the Select class:
Select select = new Select(driver.findElement(By.id("country")));
select.selectByVisibleText("India");
Methods available: selectByValue(), selectByIndex(), selectByVisibleText()
How do you handle alerts in Selenium? Medium
Selenium handles alerts using switchTo().alert():
Alert alert = driver.switchTo().alert(); alert.accept();
Methods include accept(), dismiss(), getText(), sendKeys().
How do you handle frames in Selenium? Medium
To switch to frame:
driver.switchTo().frame("frameName");
To come back:
driver.switchTo().defaultContent();
How do you handle multiple windows? Medium
Use getWindowHandles() to get all window IDs.
Switch using driver.switchTo().window(windowID).
How do you take screenshot in Selenium? Medium
Screenshots can be taken using TakesScreenshot interface:
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
What is Selenium Grid? Medium
Selenium Grid allows running test cases in parallel across multiple machines and browsers.
It improves execution speed and supports cross-browser testing.
How do you handle dynamic elements in Selenium? Hard
Dynamic elements have changing IDs or attributes.
Best practices:
Example:
//input[contains(@id,"user")]
How do you implement data-driven testing in Selenium? Hard
Data-driven testing separates test data from test logic.
Common methods:
How do you handle stale element exception? Hard
StaleElementReferenceException occurs when element is refreshed.
Solution:
Explain headless browser testing. Hard
Headless testing runs browser without GUI.
Useful for CI/CD pipelines.
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
How do you integrate Selenium with Jenkins? Hard
Steps:
This enables continuous testing.
What is the difference between findElement() and findElements()? Easy
findElement() returns a single WebElement. If the element is not found, it throws NoSuchElementException.
findElements() returns a list of WebElements. If no elements are found, it returns an empty list instead of throwing an exception.
What are relative locators in Selenium 4? Medium
Selenium 4 introduced relative locators to locate elements based on their position relative to other elements.
Example:
driver.findElement(with(By.tagName("input")).above(By.id("password")));
They improve readability but should be used carefully for stable layouts.
How do you handle file upload in Selenium? Medium
File upload can be handled by sending file path to input type="file".
driver.findElement(By.id("upload")).sendKeys("C:\file.txt");
No need to handle OS dialog if input element is accessible.
What is Fluent Wait in Selenium? Medium
Fluent Wait is a type of explicit wait that defines maximum wait time, polling frequency, and ignores specific exceptions.
Waitwait = new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(20)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class);
How do you scroll a webpage in Selenium? Medium
Scrolling can be handled using JavaScriptExecutor.
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,500)");
This is useful for lazy-loaded elements.
What is Shadow DOM and how do you handle it? Hard
Shadow DOM is used in modern web apps where elements are encapsulated inside shadow roots.
To access them, use JavaScriptExecutor:
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement shadowRoot = (WebElement) js.executeScript("return arguments[0].shadowRoot", element);
How do you handle dynamic tables in Selenium? Medium
Dynamic tables can be handled using XPath loops or iterating through rows and columns.
Example approach:
What is the difference between assert and verify? Easy
Assert stops execution if condition fails.
Verify logs failure but continues execution.
In TestNG, assertions are commonly used for validation.
How do you parameterize browser execution? Medium
Browser execution can be parameterized using TestNG XML or command-line arguments.
This helps run tests across multiple browsers dynamically.
What is the difference between WebDriver and RemoteWebDriver? Medium
WebDriver is used for local browser automation.
RemoteWebDriver is used when running tests on Selenium Grid or remote machines.
How do you design a scalable Selenium framework? Hard
A scalable framework includes:
Framework design is often asked in senior-level interviews.
How do you handle CAPTCHA in Selenium? Hard
CAPTCHA cannot be automated directly because it is designed to block bots.
Solutions:
What are common exceptions in Selenium? Easy
Common exceptions include:
How do you handle auto-suggestions in Selenium? Medium
Auto-suggestions can be handled by:
Explain cross-browser testing in Selenium. Hard
Cross-browser testing ensures application works across different browsers.
It can be implemented using:
Join our live classes with expert instructors and hands-on projects.
Enroll NowCustomized Corporate Training Programs and Developing Skills For Project Success.
Subscibe to our newsletter and we will notify you about the newest updates on Edugators