Interview prep
Selenium interview questions
Selenium interview questions for freshers test whether you can automate a browser: Selenium WebDriver basics, locators and XPath, waits, handling alerts, frames, windows and dropdowns, common exceptions, the Page Object Model and TestNG. Most answers below use Selenium 4 with Java, the stack most service companies in India ask about.
Kaabil AI builds and scores your resume, and its Career Agent emails recruiters for jobs you approve. 7 days free, no card.Start free trial
Code samples are in Java with TestNG. The ideas are the same in Python.
Basic Selenium interview questions for freshers
What is Selenium?
BasicSelenium is a free, open-source tool for automating web browsers. Testers use it to run browser tests automatically across Chrome, Firefox, Edge and Safari, in languages such as Java, Python, C# and JavaScript.
What are the components of Selenium?
Basic- Selenium WebDriver: the library that drives a real browser from your code.
- Selenium IDE: a record-and-playback tool. Current versions are a standalone app for Windows, macOS and Linux; earlier versions were Chrome and Firefox extensions.
- Selenium Grid: runs tests on many machines and browsers in parallel.
Selenium RC, the old component, has been retired.
What are the limitations of Selenium?
BasicIt tests only web applications, not desktop apps; mobile apps need Appium. It cannot read CAPTCHAs or barcodes, has no built-in reporting or test management, and needs a framework such as TestNG or JUnit to organise tests.
What is new in Selenium 4?
IntermediateWebDriver now follows the W3C WebDriver standard, there are relative locators (above, below, near and so on), you can open a new tab or window directly, take a screenshot of a single element and use Chrome DevTools features. Grid was rebuilt, and Selenium Manager (4.6 and later) downloads the right browser driver for you, and since 4.11 can fetch the browser too.
What is the difference between driver.close() and driver.quit()?
Basicclose() closes only the current browser window. quit() closes every window opened by that driver and ends the WebDriver session. Call quit() at the end of a test so no browser processes are left running.
What is the difference between driver.get() and driver.navigate().to()?
BasicBoth open a URL and wait for the page to load. navigate() also gives you back(), forward() and refresh(), so it is used when the test moves through browser history.
How do you launch a browser with Selenium WebDriver?
BasicCreate a driver object for the browser. In Selenium 4.6 and later, Selenium Manager finds or downloads the matching driver, so no manual driver path is needed.
WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("https://example.com");
Locator and XPath questions
What locators does Selenium support?
Basicid, name, className, tagName, linkText, partialLinkText, cssSelector and xpath. Prefer id or name when they are unique and stable, then CSS selectors; use XPath when you need text or to move up the DOM.
What is the difference between absolute and relative XPath?
BasicAbsolute XPath starts from the root with a single slash and lists every step, so it breaks when the layout changes. Relative XPath starts with a double slash and finds the element from anywhere in the page, so it is shorter and more stable.
/html/body/div[2]/form/input (absolute) //input[@id='email'] (relative)How do you write XPath using text, contains and starts-with?
IntermediateUse text() for exact visible text, contains() for part of an attribute or text, and starts-with() when the start of a value is fixed but the end changes.
//button[text()='Login'] //a[contains(text(),'Forgot')] //input[contains(@id,'user')] //div[starts-with(@id,'order_')]What are XPath axes?
IntermediateAxes move from one element to related ones: parent, child, ancestor, descendant, following-sibling and preceding-sibling. They help when the element you need has no unique attribute but a nearby one does.
//label[text()='Email']/following-sibling::input //td[text()='Priya']/parent::trWhat is the difference between findElement() and findElements()?
BasicfindElement() returns the first matching element and throws NoSuchElementException if there is none. findElements() returns a list of all matches, and an empty list if there are none, so it is also a safe way to check whether an element exists.
What are relative locators in Selenium 4?
IntermediateLocators that find an element by its position next to another one: above(), below(), toLeftOf(), toRightOf() and near(). They are useful when a field has no stable attribute but its label does.
WebElement password = driver.findElement( RelativeLocator.with(By.tagName("input")).below(By.id("email")));
Selenium wait questions
Why do we need waits in Selenium?
BasicPages load content at different speeds. If the script looks for an element before it appears, the test fails with NoSuchElementException even though the application works. Waits make the script pause until the element is ready.
What is the difference between implicit and explicit wait?
BasicAn implicit wait is set once for the driver and applies to every findElement call. An explicit wait waits for one specific condition on one element, such as visible or clickable. Explicit waits are more precise; do not mix the two, because the timings can add up unpredictably.
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.elementToBeClickable(By.id("submit"))).click();What is a fluent wait?
IntermediateAn explicit wait where you also set how often to check (polling) and which exceptions to ignore while waiting. Use it for elements that appear at unpredictable times.
Wait<WebDriver> wait = new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(20)) .pollingEvery(Duration.ofMillis(500)) .ignoring(NoSuchElementException.class);Why should you avoid Thread.sleep()?
BasicIt always waits the full time, even when the element is ready earlier, so tests get slow, and it still fails if the page takes longer. Explicit waits stop waiting as soon as the condition is met.
Alerts, frames, windows and dropdowns
How do you handle a JavaScript alert?
BasicSwitch to it, then accept, dismiss, read its text or type into it (for a prompt).
Alert alert = driver.switchTo().alert(); String msg = alert.getText(); alert.accept(); // OK // alert.dismiss(); // CancelHow do you handle frames (iframes)?
BasicSwitch into the frame by index, name or id, or WebElement before finding elements inside it. Use defaultContent() to go back to the main page, or parentFrame() to go up one level.
driver.switchTo().frame("payment-frame"); driver.findElement(By.id("card")).sendKeys("4111"); driver.switchTo().defaultContent();How do you switch between browser windows or tabs?
IntermediategetWindowHandle() returns the current window id and getWindowHandles() returns all of them. Loop through the set and switch to the one that is not the parent.
String parent = driver.getWindowHandle(); for (String handle : driver.getWindowHandles()) { if (!handle.equals(parent)) driver.switchTo().window(handle); }How do you select a value from a dropdown?
BasicFor a standard <select> element, use the Select class: selectByVisibleText(), selectByValue() or selectByIndex(). Custom dropdowns built with div elements are clicked like any other element.
Select city = new Select(driver.findElement(By.id("city"))); city.selectByVisibleText("Pune");How do you upload a file with Selenium?
IntermediateFind the <input type="file"> element and send it the full file path with sendKeys(). Selenium cannot operate the operating system's file dialog itself.
Actions, JavaScript and screenshots
What is the Actions class used for?
IntermediateFor mouse and keyboard gestures: hover (moveToElement), right-click (contextClick), double-click, drag and drop, and key combinations. Chain the steps and end with perform().
new Actions(driver).moveToElement(menu).click(subMenu).perform();When do you use JavascriptExecutor?
IntermediateWhen normal WebDriver commands cannot do the job, such as scrolling to an element or clicking one that is covered. Use it sparingly: a real user cannot click hidden elements, so it can hide genuine bugs.
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);How do you take a screenshot in Selenium?
BasicCast the driver to TakesScreenshot and call getScreenshotAs(). In Selenium 4 a WebElement can take its own screenshot too.
File shot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Exceptions, frameworks and TestNG questions
What is a StaleElementReferenceException?
IntermediateIt happens when an element you found earlier is no longer attached to the page, usually because the page refreshed or the element was re-rendered. Find the element again, or wait for the new one, before using it.
Name some common Selenium exceptions.
BasicNoSuchElementException (element not found), TimeoutException (a wait ran out), ElementNotInteractableException (found but cannot be used, for example hidden), StaleElementReferenceException and NoAlertPresentException.
What is the Page Object Model (POM)?
IntermediateA design pattern where each page of the application gets its own class holding that page's locators and actions. Tests call methods such as loginPage.login(user, pass), so when the UI changes you update one class instead of every test. PageFactory with @FindBy is one way to set it up in Java.
What are the main TestNG annotations, in order?
Intermediate@BeforeSuite, @BeforeTest, @BeforeClass, @BeforeMethod, then @Test, then @AfterMethod, @AfterClass, @AfterTest and @AfterSuite. @BeforeMethod and @AfterMethod run around every @Test, which makes them the usual place to open and quit the browser.
What is the difference between hard assert and soft assert?
IntermediateA hard assert (Assert.assertEquals) stops the test at the first failure. A soft assert (SoftAssert) records failures and lets the test continue; call assertAll() at the end to report them.
How do you run tests with different data in TestNG?
IntermediateUse a @DataProvider method that returns rows of test data, and point the @Test at it with dataProvider. The test runs once for each row, such as different username and password pairs.
How do you run tests in parallel?
AdvancedSet parallel="methods", "classes" or "tests" and a thread-count in testng.xml, and keep one WebDriver per thread (for example with ThreadLocal). To run across machines and browsers, use Selenium Grid.
How do you handle a CAPTCHA in automation?
BasicYou do not automate it: CAPTCHAs exist to stop bots. Ask the developers to disable CAPTCHA in the test environment or provide a test key, and test the CAPTCHA itself manually.
How to prepare for a Selenium interview
Be solid on core Java first: classes and objects, inheritance, interfaces, collections (List, Set, Map) and exception handling. Selenium rounds often start with Java questions.
Automate one real flow end to end, such as login, search and add to cart on a demo shopping site, using explicit waits and no Thread.sleep().
Turn it into a small framework: Page Object Model, TestNG with a testng.xml, a DataProvider and screenshots on failure. Put it on GitHub and mention it on your resume.
Practise writing XPath and CSS selectors by hand for tricky elements: dynamic ids, tables and elements found through a label.
Revise manual testing basics too, because most automation interviews include them. Start with our manual testing interview questions.
Is Selenium with Java or Python better for freshers?
Both work, and the Selenium concepts are the same. Java with TestNG is the most common stack in job posts at Indian service companies, so it is the safer choice if you are applying widely. Python is quicker to learn and common at startups. Pick one, build a project with it and learn it well.
Kaabil App
Prove your skills before the interview.
Take skill assessments in the Kaabil AI app. Passed checks become certificates from Kaabil AI by Redrob, with a verification link.
See the Kaabil App7 days free · No card
Questions freshers ask
Locators and XPath, implicit versus explicit waits, close() versus quit(), handling frames, windows and alerts, findElement versus findElements, StaleElementReferenceException, the Page Object Model and TestNG annotations.
Yes. You cannot automate a test you cannot design, so interviewers check test case design, the bug life cycle and types of testing as well as Selenium itself.
Yes. It is free, supports every major browser and language, and remains widely listed in automation testing job posts. Newer tools such as Playwright and Cypress are growing, and the skills you learn with Selenium carry over to them.
The part of Selenium that runs tests on several machines and browsers at the same time. A central hub (or router) sends each test to a node that has the browser it needs, which cuts the time a large test suite takes.