50+ Most Important Selenium WebDriver Interview Questions and Answers

This Selenium Interview questions post will definitely help you prepare for Selenium automation interview and brush up your selenium skills easily. You can find Selenium interview questions and answers and also Selenium Java interview questions from Experienced to beginners on this post. Selenium interview questions are divided into different topics for sake of ease.

Table of Contents

1. Selenium WebDriver Commands Interview Questions

2. Actions Class Interview Questions

3. Selenium Locators Interview Questions

4. Windows and Frame Handling Interview Questions

5. TestNG Interview Questions

6. Advanced Selenium Interview Questions

7. OOPS, Selenium Automation Framework and Project related Interview Questions

Selenium Video Tutorials Playlist (YouTube)

1. Selenium WebDriver Commands Interview Questions

Q1 - What is the syntax to launch browser in Selenium WebDriver?

We can launch browser by creating an object of WebDriver interface and initialize it with some browser class like., ChromeDriver(), FirefoxDriver() etc. Please see the syntax for different browsers,

// Set Path of driver executable
String driver_executable_path = "./src/com/techlistic/utils/geckodriver.exe";
System.setProperty("webdriver.gecko.driver", driver_executable_path);
// Launch Browser - Creating a Firefox instance
WebDriver driver = new FirefoxDriver();

// For Chrome
String driver_executable_path = "./src/com/techlistic/utils/chromedriver.exe";
WebDriver driver = new ChromeDriver();

// For Safari
String driver_executable_path = "./src/com/techlistic/utils/safaridriver.exe";
WebDriver driver = new SafariDriver();

// For Opera
String driver_executable_path = "./src/com/techlistic/utils/operadriver.exe";
WebDriver driver = new OperaDriver();

// For IE
String driver_executable_path = "./src/com/techlistic/utils/iedriver.exe";
WebDriver driver = new InternetExplorerDriver();

Q2 - What is the difference between driver.get() and driver.navigate().to() commands?

Q3 - What are the different navigation commands used in Selenium WebDriver?

There are 4 navigation commands in Selenium WebDriver,

	// Navigate directly to some URL

	// Navigate Back

	// Navigate Forward

	// Refresh Page

Q5 – What is the difference between driver.close() and driver.quit() Selenium WebDriver?

i. driver.close() - It is used to close the current browser window.

ii. driver.quit() - It is used to close all the browser windows which are opened by Selenium and safely ends the session. (Destroys the WebDriver instance)

Q6 - How to enter the text in a text field using Selenium WebDriver?

We can enter text in Selenium by using sendKeys() command.

driver.findElement(By.xpath("/some/xpath")).sendKeys("Some Value");

// OR

// Implementation with WebElement
WebElement FIRSTNAME =  driver.findElement(By.id("some-id"));
FIRSTNAME.sendKeys("Any Text value");

Q7 - How to check that the radio button is checked or not?

You can use isSelected() command of Selenium to see whether a radio button is checked or not.

/* isSelected()

WebElement gender =  driver.findElement(By.id("some-radio-button-id"));
boolean isGenderSelected = gender.isSelected();

Q8 - How to get color or size of the font Selenium WebDriver? (how to get background color or any other css property of the web element)

We can get the font color or size or any other css property value of web element by using getCssValue() command.

/* getCssValue() Command
WebElement HEADING =  driver.findElement(By.id("some-id"));

String color = HEADING.getCssValue("color");

Q9 - How to validate any error/success message in Selenium WebDriver?

Selenium provides getText() command by using that, we can get text of the error/success message and validate it with the expected message.

String textValue = driver.findElement(By.xpath("/some/xpath")).getText();

// OR

// Implementation with WebElement
WebElement SOME_LINK =  driver.findElement(By.id("some-id"));
String linkValue = SOME_LINK.getText();

Q10 - How to select an item from the drop down menu with Selenium WebDriver? What are the different commands to select an item?

We have create the object of Select class in Selenium and then we can select an element from Select drop down menu by using any one of the following three commands:

/* Select Commands
 *  selectByIndex()
 *  selectByVisibleText()
 *  selectByValue()
WebElement DROP_DOWN = driver.findElement(By.xpath("/select"));

// Create object of Select Class
Select select1 = new Select(DROP_DOWN);

// Option 1

// Option 2

// Option 3

Q11 - How to check the text is present/visible or not on page?

We can check presence of text on a page by using isDisplayed() command.

/* isDisplayed()
WebElement loginButton =  driver.findElement(By.id("some-id"));
boolean isLoginDisplayed = loginButton.isDisplayed();

Q12 - How to handle Alerts or Pop-Ups using Selenium WebDriver?

Alerts or javascript pop-ups can be handled by using commands of org.openqa.selenium.Alert class in Selenium WebDriver. For details read here - Alert Handling

// Alert class object creation
// Below Code switches the control/focus of your execution to the alert
Alert alert = driver.switchTo().alert();

// Below command is used to accept the alert like click on Yes, Accept, Ok button

// Below command is used to dismiss/reject the alert like click on No, Dismiss, 
Cancel button

Q13 - Why we aren't recommended to use Thread.sleep() in Selenium?

Thread.sleep() pauses the execution flow of the thread for particular time, which is not the ideal way to wait. Instead of that some of the Selenium wait should be used.

Q14 – What are the different wait commands in Selenium WebDriver?

There are three types of wait commands in Selenium: (Read in detail – Selenium Wait Commands):

1. Implicit Wait - Implicit wait is used to set wait time (say 30 secs) in your automation script to wait for an  element on the page before throwing exception. You can increase or decrease the wait time as per your requirement.

2. Explicit Wait – Explicit wait is also knows as conditional wait. It directs the Selenium WebDriver to wait until a condition is met.

3. Fluent Wait - Fluent wait is kind of conditional wait but with frequency.

Q15 – What is the syntax for implicit, explicit and fluent wait?

Syntax for Implicit, Explicit and Fluent wait commands:

// Implicit wait - Set wait of 10 seconds
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Explicit Wait
 WebDriverWait wait = new WebDriverWait(driver, 10); 

// Fluent Wait
 Wait wait = new FluentWait(WebDriver reference)
   .withTimeout(timeout, SECONDS)
   .pollingEvery(timeout, SECONDS)

 WebElement foo = wait.until(new Function() {
  public WebElement apply(WebDriver driver) {
   return driver.findElement(By.id("foo"));

Q16 - How to handle ajax elements using Selenium WebDriver?

When we do Google search and a list of options matching to our keyword displayed on it's own without refreshing the page, is an example of ajax search. We can handle ajax elements using Explicit Wait in Selenium. Read in detail - Automating Google Search using Explicit Wait

In following code, we are typing keyword "selenium tutorial techlistic" in google search box. And then suggestion box appears and we are handling that ajax suggestion box with the WebDriverWait class's presenceOfElementLocated() function.

//enter techlistic tutorials in search box
	driver.findElement(By.name("q")).sendKeys("selenium tutorial techlistic");

	//wait for suggestions
	WebDriverWait wait=new WebDriverWait(driver, 20);

	WebElement list=driver.findElement(By.className("sbtc"));
	List rows=list.findElements(By.tagName("li"));

	for(WebElement elem:rows) {

Q17 - How to scroll vertically and horizontally using Selenium WebDriver?

We can do scroll in selenium using org.openqa.selenium.JavascriptExecutor. It is a Selenium interface which can be used to execute any javascript code snippet. We use executeScript() method of it to execute javascript code for vertical or horizontal scroll.

   // Create object of JavascriptExecutor
  JavascriptExecutor js = (JavascriptExecutor) driver;

  // Vertical Scroll

  // Horizontal Scroll

Q18 - How to take screenshot in Selenium WebDriver?

Screenshot can be taken by using org.openqa.selenium.TakesScreenshot class of Selenium.
Read in detail - Take Screenshot in Selenium

In the following code, we are creating object of the File class of Java and storing the screenshot take using the TakesScreenshot's getScreenShotAs() method. And then storing it with some name using the FileUtils class's copyFile() method of Java.

// Create File object and save screenshot of current webpage inside it
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

// Copy screenshot file to a location with some name and extension you want
FileUtils.copyFile(screenshot, new File("D:\\screenshot.jpg"));

 Q19- What are the advantages of using Selenium WebDriver?
  • Selenium is open source.
  • It has huge support from the community, means if you stuck at some point while working on it, you can get answers for your problem from internet easily as, a lot people are working on it.
  • It supports multiple languages like., Java, Python, C#, Ruby, Perl etc.
  • It supports almost every browser., like firefox, chrome, edge, safari etc.
  • Regular updates.
  • Easy to maintain the code.
  • It reduces the time and effort with respect to Manual testing.

Q20- What are the dis-advantages of using Selenium WebDriver?
  • We can only test web applications with Selenium and cannot automate Mobile or Desktop applications.
  • No reporting mechanism available. We have to integrate third party tools like TestNG or Allure for reporting.
  • No in-built logging mechanism.
  • One should have basic knowledge of HTML to locate elements.
  • One should have proper knowledge of any programming language.
Q21- What is Selenese?
Selenese is the set of Selenium commands. We can divide Selenese or Selenium commands into three categories:
  • Actions - They are used to perform interactions with web elements.
  • Accessors - They are used to store values in variables.
  • Assertions - They are used to validation.
Q22- Can you name some of the Selenium exceptions?
  • TimeoutException
  • WebDriverException
  • NoAlertPresentException
  • NoSuchWindowException
  • NoSuchElementException

Q23- What is Desired Capabilities in Selenium WebDriver?
DesiredCapabilities is a class in Selenium which is used to set/get browser properties or you can also say it is used for setting the configuration of the browser before running selenium tests on it. You can set accept ssl errors, enable/disable alerts, set browser name or version etc.

Q24- Can we perform Database testing with Selenium?
Selenium itself doesn't support database testing, but we can perform database testing using any language's database library. Like if we are using Selenium with Java then we can use Java's JDBC library to write out database tests. JDBC allows us to execute the SQL queries and we can verify the SQL query results.

Q25- Can we handle window dialogs using Selenium?
No window cannot interact with window dialogs on its own. That's why upload file dialogs or download file dialogs can't be handled with Selenium. But we can handle them in the Selenium script by using third party tools or some other Java libraries. Like., we can make use of the Robot Class library of Java to handle those dialogs or we can use third party tool AutoIT to handle such window dialogs. We can integrate AutoIT code inside the Selenium WebDriver code.

Q26 - What different types of testing can be done using Selenium?
Selenium is basically used for Functional testing and it doesn't support non-functional testing like Performance testing, UI testing, Usability testing, Security testing. And in functional testing it is mostly used for automating
  • Regression Testing
  • Smoke Testing
  • Sanity Testing

2. Actions Class Commands Interview Questions

Q1 - What is Actions class? What are its commands?

Actions class is used to handle Keyboard and Mouse Events. You need to import org.openqa.selenium.interactions.Actions in order to use Actions class. 
This class includes keyboard and mouse actions such as double click, right click, drag & drop, mouse hover and clicking multiple elements.

Q2 - What are the keyboard and mouse events in Selenium WebDriver?

We can perform following Keyboard and Mouse events using Actions class:

i. Keyboard events: You can press any key of the keyboard, 
  • Key Up
  • Key Down
  • sendKeys()
ii. Mouse events:
  • click()
  • doubleClick()
  • contextClick()
  • clickAndHold()
  • dragAndDrop()
  • moveToElement()
  • moveByOffset(x, y)
  • release()

Q3 - How to do Mouse hover in Selenium WebDriver?

We can perform Mouse Hover using Actions class in Selenium WebDriver. Let's take a look at the code to do so, ( Read in detail - Actions Class Mouse Hover Command )

/* Mouse Hover

// Xpath for Menu
WebElement Menu_Link = driver.findElement(By.xpath("/html/some/xpath"));

// Xpath for Sub Menu
WebElement SubMenu_Link = driver.findElement(By.xpath("/html/some/xpath"));

// Create object of Actions class
Actions actions = new Actions(driver);

// Move cursor to Menu link (Mouse hover on menu link so that sub menu is displayed)

// Click on Submenu link (whcih is displayed after mouse hovering curson on menu link)

Q4 - How to do double click and right click in Selenium WebDriver?

i. Double Click - We can perform double click by using Action class's doubleClick() method.

/* Double Click
Actions actions = new Actions(driver);
WebElement PRODUCT_CATEGORY = driver.findElement(By.xpath("/html/some/xpath"));

ii. Right Click - We can perform right click by using Action class's contextClick() method.

/* Right Click

// Locate web element
WebElement PRODUCT_CATEGORY = driver.findElement(By.xpath("/html/some/xpath"));

// Create object of actions class
Actions actions = new Actions(driver);

// Right click on PRODUCT_CATEGORY element

Q5 - How to drag and drop an element in Selenium?

We can perform drag and drop using Action class's.

/*   Drag And Drop

// Weblements for source and target
WebElement source = driver.findElement(By.name("source"));
WebElement target = driver.findElement(By.name("target"));

// Create object of actions class
Actions action = new Actions(driver);
action.dragAndDrop(source, target);

3. Selenium Locators Interview Questions

Q1 - What is the difference between findElement() and findElements() in Selenium WebDriver?
i. findElement() - It is used to locate single element on the web page. It returns single WebElement.

ii. findElements() - It is used to get all the webelements having same element locator. For e.g., if we would use driver.findElements(By.id("text")), then it will return list of all the web elements present on the web page having id "text".

Q2 - How many different types of locators are in Selenium?
There are 8 different type of locators that can be used in Selenium to find an element. (Read in detail - Different Selenium Locators)
  1. ID
  2. Name
  3. Link Text
  4. Partial Link Text
  5. Tag Name
  6. Class Name
  7. CSS Selector
  8. XPath

Q3 - Which one is the fastest and slowest locator?
Generally, ID is considered as the fastest and xpath is considered as the slowest locator. But when it comes to choose a locator for your automation, we should pick the most reliable one which is of course ID.
Q4 - What are the different types of xpaths and what is the difference between them?
XPATH is also known as Extensible Markup Language Path. It's a language by using which we can query xml documents and can locate elements in Selenium. There are two types of xpaths, 

i. Absolute xpath - It starts with single slash '/', and it starts from the first tag which is html tag. Ex., /hml/body/div[3]/input

ii. Relative xpath - It starts with double slash '//', relative path can be created from anywhere in the web page. Ex., //div[@id='name']/div/span/input

4. Windows and Frame Handling Interview Questions

Q1 How to switch to Nth browser window in Selenium WebDriver?

Case 1 -

// Create a Set and store all window handle ids in it

Set AllWindowHandles = driver.getWindowHandles(); 
String window1 = (String) AllWindowHandles.toArray()[0]; 
String window2 = (String) AllWindowHandles.toArray()[1]; 

// Switch to window with id 2 driver.switchTo().window(window2);
String window1 = (String) AllWindowHandles.toArray()[0];
String window2 = (String) AllWindowHandles.toArray()[1];

// Switch to window with id 2

Case 2 -

/* Moving Between all Windows
for (String handle : driver.getWindowHandles()) { driver.
driver.switchTo().window(handle); }

Q2 - How to switch frames in Selenium WebDriver?

Switch frames can be done using switchTo() method.
  // Move to frame
 driver.switchTo().frame("Target Web element")

5. TestNG Interview Questions

Q1 - What is TestNG? What are it's important features?

TestNG is a unit testing framework which is developed in lines of JUNIT and NUNIT, however it introduces some new functionalities that makes it more powerful and easy to use. It is designed to cover all categories  of tests − unit, functional, end-to-end, integration, etc., and it requires JDK 5 or higher. (Read in detail - Selenium-TestNG Integration)

Features of TestNG:
  • Flexible test configuration
    • (with annotations @BeforeMethod, @Test, @AfterMethod etc)
  • Support for data-driven testing
    • (with @DataProvider)
  • Support for annotation parameters
  • Support for method dependency
    • (with @dependsOnMethods)
  • Support for defining execution Priority of test methods
    • (with @priority)
  • Supported by a variety of tools and plug-ins
    • (Eclipse, IDEA, Maven, etc)
  • Support for default Test Reporting in HTML and XML formats.
  • Default JDK functions for runtime and logging (no dependencies)

Q2 - What are the different annotations in TestNG?

Some of the important annotations of TestNG are:
  • @BeforeClass
  • @AfterClass
  • @BeforeMethod
  • @AfterMethod
  • @Test
  • @priority
  • @dependsOnMethods
  • @DataProvider

Q3 - What are setup and teardown methods in Selenium? How to create setup and teardown methods using TestNG in Selenium?

i. Setup Method - In setup method we do those operations which are pre-requisite for our test method. Because we want our setup method to be executed before our test method. For e.g., if we talk about creating a setup method in Selenium, then we would initiate a WebDriver object and open the URL of the website which we want to test in out test method or we can also do login in our setup method. We can use any @Before annotation like @BeforeMethod or @BeforeClass as per our requirement.  (Read - Selenium-TestNG Program Example)

ii. TearDown - We want our tear down method to be executed after our test execution has finished. So, in tear down method we put that code which is required to be executed after finishing out our test like., logout of your application, close db or file connections if you create any during your test execution and close the browser. We can use @AfterClass or @AfterMethod annotation to create tear down method.

Let's understand the use of setup and teardown from following coding example, here setup will be executed before test method and teardown method will be executed after test method.

public class TestNGAnnotations {
 WebDriver driver;
 public void setup() {
  // Set Chrome driver property
  System.setProperty("webdriver.chrome.driver", "D:\\mydir\\chromedriver.exe");
  // Launch chrome browser
  driver = new ChromeDriver();

  // Opening Browser URL and maximize it
  // Put login code here

 public void test_HomePage() {
  // Put here WebDriver code to test your functionality

 public void teardownClass() {
  // Put logout code here

  // Close all WebDriver instances

Q4 - What is the difference between @BeforeClass, @BeforeMethod and @AfterClass, @AfterMethod in TestNG?

i. @BeforeClass - This method executes only once before the execution of @Test methods in the current class. No matter how many @Test methods are present in the current class, @BeforeClass method will be executed only one time.

ii. @AfterClass - This method executes only once after the execution of @Test methods in the current class. No matter how many @Test methods are present in the current class, @AfterClass method will be executed only one time.

iii. @BeforeMethod - This method executes before every @Test method in the current class. If there are 5 @Test methods present in current class, then @BeforeMethod will be executed 5 times.

iv. @AfterMethod - This method executes after every @Test method in the current class. If there are 5 @Test methods present in current class, then @AfterMethod will be executed 5 times.

Let's understand it from the following coding example. Here we have two test methods, one each BeforeMethod, BeforeClass, AfterMethod and AfterClass. Read in detail - TestNG Annotations
When we will execute this program, 
  • Then first of all BeforeClass will be executed
  • then BeforeMethod will be executed
  • then testF() will be executed (because it comes first alphabetically)
  • then AfterMethod will be executed
  • then again BeforeMethod will be executed
  • then testG() will be executed
  • then again AfterMethod will be executed
  • And in the end, AfterClass will be executed

public class TestClass {

  public void testF() {
   System.out.println("f Test Method");
  public void testG() {
   System.out.println("g Test Method");
  public void setupMethod() {
   System.out.println("Before Method");

  public void teardownMethod() {
   System.out.println("After Method");

  public void setup() {
   System.out.println("Before Class");

  public void teardown() {
   System.out.println("After Class");

Q5 How can we generate Test Report in TestNG?

TestNG generates test report by itself when we execute any test. It generates test report in two formats, HTML and XML.

Q6 How to set priority of test methods execution in TestNG?

We can set priority of execution of test methods by using @priority annotation. We can set priority of any test method by setting any int value like, @priority=1. Lower the value of @priority, higher the priority.

  public void three() {
   System.out.println("This is test case 3");

Q7 - What is the difference between assert and verify?

Assert - Assert statement fails the script and stops the script execution if
assert condition fails.

Verify - In case of verify, it logs the failure in the final result but does
not stops the script execution on verify statement failure.

6. Advanced Selenium Interview Questions

Q1 How to download a file using Selenium WebDriver?

Selenium can't directly interact with window dialogues but we can interact with them by keyboard interactions using Selenium's Keys class or Java's Robot class.

You can download a file using Robot class of Java.

/* Download file by clicking on Save button of window dialog
 // Create object of Robot class
 Robot r = new Robot();  
 // Press Alt and S key, it will shift the focus to 'Save' button of Windows dialog
 // Now, release S and Alt key
 // Press Enter Key as Focus is on Save button, so it will be 
 // Release Enter key

Q2 - How to upload a file with Selenium WebDriver?

Selenium can't directly interact with window dialogues but we can interact with them by keyboard interactions using Selenium's Keys class or Java's Robot class.

Q3 - How to find broken links of a web page using Selenium WebDriver?

Q4 - How to Handle Multiple Browser Tabs Using Selenium WebDriver?

Multiple browser tabs can be handled using Keys enumerator and switchTo() method. 
Read in detail- Multiple Browser Tabs Handling 

Q5 - How to Achieve Code Re-useablity & Maintainability in Selenium Code?

Code re-usability can be achieved by creating page methods (action methods) and use those methods in your test method code instead of direct selenium commands.

Q6 - How to Handle Dynamic Web Table in Selenium WebDriver?

We can handle dynamic web table by preparing dynamic XPATHof table at runtime. 
Read in detail - Handle Dynamic Table

Q7 - How to Extract Table Data/Read Table Data Using Selenium WebDriver?

We can extract table data by preparing dynamic xpath of table at runtime. 
Read in detail - Extract Table Data

Q8 - How to Take Partial Screenshot in Selenium WebDriver?

Partial screenshot can be taken by using org.openqa.selenium.Point class of Selenium. We can get height and width of the element by using Point class. 
Read in detail - Take Partial Screenshot

7. OOPS, Selenium Automation Framework and Project related Interview Questions

Q1 - How to implement oops concepts  in selenium?

You can explain your existing framework and how OOPS concepts are implemented in it.

Q2 - What are the different types of automation frameworks?

There are different types of automation frameworks, but most commonly used are,

Linear Framework
Keyword Driven Framework
Modular Framework
Data Driven Framework
Page Object Model
Hybrid Framework

Q3 - What automation framework do you use in your project and what are the important components of that framework?

You can answer this with regards to your automation framework.

Q4 - How many test cases do you automate daily?

Generally this answer depends on the complexity of the feature that you are automating. But if the feature is not much complex then you can automate 2-3 test cases a day.

Q5 - How you can automate CAPTCHA?

No, we can't automate CAPTCHA. In fact captcha is placed to restrict the automation of that page.

Q6 - How your framework is integrated with your CI/CD pipeline? And which tool are you using for CI/CD?

There are different CI/CD tools present in the market like., Jenkins, Bamboo, GitLab etc. You can explain about your project's tool. Good luck for your interview!

Passionately working as an Automation Developer from more than a decade. Let's connect LinkedIn

    Follow Us

    YouTube Channel | Facebook Page | Telegram Channel | Quora Space
    Feel free to ask queries or share your thoughts in comments or email us.


    1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

      Selenium Certification Training in Electronic City

    2. Thank you for sharing such a useful article. I had a great time. This article was fantastic to read. Continue to publish more articles on
      Cracking The Coding Interview
      data structures and algorithms

    3. Thanks for publishing such great information. You are doing such a great job. This information is very helpful for everyone. Keep sharing about Website Development Service Provider. Thanks.

    4. I sincerely believe that a day will come when every big decision and life changing events will originate from our sucessful use of Internet. etvbharat com

    5. The cost of an Insurance Policy for your family would be about $12,000. What Is The Cost Of Vyvanse Without Insurance


    Post a Comment

    Popular posts from this blog

    10+ Best Demo Websites for Selenium Automation Testing Practice

    Automate Amazon like E-Commerce Website with Selenium WebDriver

    Handle Static and Dynamic Web Table in Selenium WebDriver

    25+ Most Important Selenium WebDriver Commands Tutorial

    Top 7 Web Development Trends in 2022

    How to Automate Google Search with Selenium WebDriver

    How to Find Broken Links on Webpage with Selenium WebDriver