Daily 10 Selenium Interview Questions - Part 1

 

Daily 10 Selenium
Interview Questions - Part 1

I am happy to start a new series today: "Daily 10 Selenium Interview Questions". If you're preparing for a QA or Automation Testing role, especially where Selenium is a must-have skill, this series is just for you. Every day, we’ll go through 10 commonly asked Selenium interview questions, keeping things simple, clear, and helpful, just like talking chai with a friend before interviewing!

Whether you're a fresher or have a few years of experience, daily practice of these questions will help you build confidence and stay sharp.


seleniumIQPart1


1. What does Selenium mean?

Selenium is a tool that helps in automating what happens when we use a web browser. The platform can work with programs written in Java, Python and C#. It lets testers design scripts that stand in for users by clicking buttons, typing text and going between web pages.

2. What are the elements part of Selenium?

Selenium consists of four main parts.

  1. With Selenium IDE, you can use your Firefox/Chrome browser to create and play back tests.
  2. The current version of Selenium uses WebDriver and leaves legacy support for RC (now not supported).
  3. Selenium WebDriver helps automate web browser tasks by writing code.
  4. Selenium Grid is used when we need to run tests simultaneously on different machines and browsers.

3. What does Selenium WebDriver refer to?

The tool Selenium WebDriver is used to automate testing of web applications. It communicates closely with the browser and takes control of the user’s actions. It works more quickly and is more dependable than Selenium RC.

4. Can Selenium manage pop-up windows on Windows computers?

The answer is no, as Selenium can manage Windows pop-ups through web browsers, but not instantly. For these kinds of situations, you rely on software like AutoIT or Robot Class in Java. Here's a simple example using Robot Class in Java: 

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.event.KeyEvent;


public class RobotPopupHandler {


public static void main(String[] args) throws AWTException, InterruptedException {

Robot robot = new Robot();

Thread.sleep(2000); // wait for popup to appear

// Press Enter key to accept alert or popup

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);


}

}

5. How is it possible to work with list selection boxes in Selenium?

The Select class from Selenium lets us manage dropdowns. We have the choice to use visible text, index or value to select options within this class. Here's a sample code snippet:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;


public class DropDown {


public static void main(String[] args) {

WebDriver driver = new ChromeDriver();

driver.get("https://example.com");


// Locate the dropdown element

WebElement dropdown = driver.findElement(By.id("dropdownId"));


// Create a Select object

Select select = new Select(dropdown);


// Select by visible text

select.selectByVisibleText("Option 1");


// Select by index

select.selectByIndex(2);


// Select by value

select.selectByValue("option3");


driver.quit();

}

}

6. What does a locator mean in Selenium?

The purpose of locators is to highlight the elements found on a web page. Common ways to locate funding are through:

  1. ID
  2. Name
  3. Class Name
  4. Tag Name
  5. Link Text
  6. Partial Link Text
  7. CSS Selector
  8. XPath

7. How are driver.get() and driver.navigate().to() different?

Both helper functions launch the URL in the browser, but navigate().to() is more flexible and works with the browser’s forward/back functions, while get() is simpler and just opens a URL.

8. When working with Selenium, how do you deal with alerts?

You manage alerts by using the Alert interface. Run driver.switchTo().alert() to switch to the alert and from there, you can accept or dismiss it.

9. What’s a difference between the findElement() and findElements() commands.

findElement() gives you one element. If it doesn’t find anything, it will throw an error. On the other hand, findElements() gives you a list of elements. If there’s nothing to find, it just gives you an empty list — no error.

10. What are different types of waits in Selenium and where do we use them?

In Selenium, there are three types of waits:

Implicit Wait – Tells WebDriver to wait for a certain time when searching for an element. It applies globally to all elements. 
Use Implicit Wait for general delays across the test.
Syntax: driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

Explicit Wait – Used to wait for a specific condition to happen before proceeding. This is more flexible and used when certain elements take longer to load.
Use Explicit Wait when waiting for specific elements like buttons or drop downs that may load dynamically.
Syntax:     
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
element.click();

Fluent Wait – Similar to Explicit Wait, but with polling frequency and the ability to ignore specific exceptions while waiting.
Use Fluent Wait when you need to wait with custom polling time and exception handling.
Syntax:
FluentWait<WebDriver> wait = new FluentWait<>(driver)
            .withTimeout(Duration.ofSeconds(10))
            .pollingEvery(Duration.ofSeconds(2))
            .ignoring(NoSuchElementException.class);

   WebElement element = wait.until(new Function<WebDriver, WebElement>() {
    public WebElement apply(WebDriver driver) {
        return driver.findElement(By.id("elementId"));
        }});
    element.click();
Note: If the element is found before the wait time ends, WebDriver will not wait the full duration — it will move to the next step immediately.

Wrapping Up

Practising daily is the best way to prepare for interviews. Bookmark this page and I’ll pick things up in Part 2 tomorrow. Also, don’t forget to share this with your friends or colleagues who are also preparing for QA/SDET roles. I’ll be back again tomorrow with 10 more questions. Wishing you all the best for your learning until then.

Previous Post Next Post