Selenium Java Interview Questions And Answers : That Every QA should Know (Top 51+ Questions)

We are going to learn about the TOP 51+ Selenium Selenium Java Interview Questions and Answers. These are exact questions asked for the beginners and experience people. 

You can download the selenium java interview questions and answers for experienced as PDF also in below link.



Question #1 : What is Selenium WebDriver?

  • It is an automation framework that allows you to execute your tests against different browsers.

  • WebDriver also enables you to use a programming language in creating your test scripts

    • Java, .Net, PHP, Python, Ruby, Perl

  • It supports Chrome ,Firefox ,Opera , Safari , IE , HTML unit driver(headless)

Selenium Java Interview Questions And Answers


​Question #2 : What are the different types of exceptions you have faced in Selenium WebDriver?

  • NoSuchElementException
  • NoSuchWindowException
  • NoSuchFrameException
  • NoAlertPresentException
  • ElementNotVisibleException
  • ElementNotSelectableException
  • TimeoutException
Selenium Exception Hierarchy


​Question #3 : What is implicit wait in Selenium WebDriver?`

The implicit wait will tell the WebDriver to wait a certain amount of time before it throws a “No Such Element Exception.” 

The default setting of implicit wait is zero. Once you set the time, the web driver will wait for that particular amount of time before throwing an exception.


driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


​Question #4 : What is WebDriver Wait in Selenium WebDriver?

Explicit waits are a concept from the dynamic wait, which waits dynamically for specific conditions. It can be implemented by the WebDriverWait class

WebDriverWait wait = new WebDriverWait(driver, 20);

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(“input”)));


​Question #5 : What is Fluent Wait in Selenium WebDriver?

fluent wait selenium

Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. 


Wait wait = new FluentWait(driver)
 .withTimeout(30, SECONDS)

.pollingEvery(5, SECONDS)


WebElement element = wait.until(new Function()


       public WebElement apply(WebDriver driver) {

          return driver.findElement(“element”));




​Question #6 : How to Input Text into a value by Javascript?

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById("<<inputbox_id>>").value='new value’”);


​Question #7 : How to get an attribute value of an element using Selenium WebDriver?



​Question #8 : How to Send Keyboard keys like press Enter key on text box in Selenium WebDriver?



​Question #9 :   What is the difference between driver.get(“URL”) and driver.navigate().to(“URL”) commands?

driver.get() is used to navigate particular URL(website) and wait till page load.

driver.navigate() is used to navigate to particular URL and does not wait to page load. It maintains browser history or cookies to navigate back or forward.


​Question #10 : How to pause a test execution for 5 seconds at a specific point?

We can pause test execution for 5 seconds by using the wait command.




​Question #11 : What is Selenium Grid and when do we go for it?

selenium grid explained

Selenium Grid is used to run tests on different machines against different browsers in parallel. We use Selenium Grid in the following scenarios:

Execute your test on different operating systems
Execute your tests on different versions of same browser
Execute your tests on multiple browsers
Execute your tests in parallel and multiple threads


​Question #12 : What is a Hub in Selenium Grid?

  • Hub is the central point to the entire GRID Architecture which receives all requests.
    There is only one hub in the selenium grid. Hub distributes the test cases across each node.


​Question #13 : What is a Node in Selenium Grid?

There can be multiple nodes in Grid.
Tests will run in nodes.
Each node communicates with the Hub and performs test assigned to it.


​Question #14 : Which WebDriver implementation claims to be the fastest?

HTML UnitDriver is the most lightweight and fastest implementation headless browser for of WebDriver. It is based on HtmlUnit.
It is known as Headless Browser Driver.
It is same as Chrome, IE, or FireFox driver, but it does not have GUI so one cannot see the test execution on screen.


​Question #15 : What are the open source frameworks supported by Selenium WebDriver?

  • TestNG
  • JUnit
  • Cucumber
  • Robot Framework
  • Appium
  • Protractor


​Question #16 : What are the different types of navigation commands in Selenium?

  • navigate().to();


Question #17 : How can we Maximize browser window in Selenium WebDriver?

  • driver.manage().window().maximize();


​Question #18 : How to delete cookies in Selenium?

Single Cookie Delete by Name
All the cookies


Question #19 : What is the difference between driver.getWindowHandle() and driver.getWinowHandles() in Selenium WebDriver and their return type?

driver.getWindowHandle() – To get the window handle of the current window. Returns a string of alphanumeric window handle

driver.getWinowHandles() – To get the window handle of all current windows. Return a set of window handles


​Question #20 : How to handle hidden elements in Selenium WebDriver?

We can use the JavaScriptExecutor to handle hidden elements.
JavascriptExecutor js = (JavascriptExecutor)driver;


​Question #21 : How to find more than one web element in the list?

We can find more than one web element by using the findElements() method in Selenium.
List<WebElement> elements = driver.findElements(By.tagName(“a”));


Question #22 : How will you find an element using Selenium?

  • ID
  • Name
  • Tag
  • Attribute
  • CSS
  • Linktext
  • PartialLink Text
  • XPath etc


Question #23 : What is the difference between verify and assert commands?

Assert: In other words, the test will terminated at the point where check fails.
Verify: In verification, all the commands are going to run guaranteed even if any of test fails.


Question #24 : Explain what are the JUnits annotation linked with Selenium?

@Before public void method() – It will perform the method () before each test, this method can prepare the test

@Test public void method() – Annotations @Test identifies that this method is a test method environment

@After public void method()- To execute a method before this annotation is used, test method must start with test@Before


Question #25 : Explain what is DataDriven framework and Keyword driven?

 Data Driven : The test data is separated and kept outside the Test Scripts, while Test Case logic resides in Test Scripts.


Keyword Driven  : The functionality of the application under test is documented in a table as well as step by step instructions for each test.


Question #26 : How you can switch between frames?

To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three possible arguments

A number: It selects the number by its (zero-based) index
A number or ID: Select a frame by its name or ID
Previously found WebElement: Using its previously located WebElement select a frame


Question #27 : How you can perform double click ?

Actions act = new Actions (driver);


Question #28 : How to read a JavaScript variable in Selenium WebDriver?

JavascriptExecutor js = (JavascriptExecutor)driver;
//Click on button using JS
js.executeScript("arguments[0].click();", button);


Question #29 : How to wait for Element to visible by a AJAX call?

WebDriverWait wait = new WebDriverWait(driver, waitTime);



Question #30 : What is Page Object Model (POM) ?

Page Object Model is a design pattern for creating an object repository for web UI elements.
Each web page in the application is required to have its own corresponding page class.
The page class is thus responsible for finding the WebElements in that page and then perform operations on those web elements.


Question #31 : What is Page Factory?

Page Factory class in Selenium is an extension to the Page Object Design pattern. It is used to initialize the elements of the page object or instantiate the page objects itself.

Annotations in Page Factory are like this:
@FindBy(id = “userName”)
WebElement txt_UserName;

PageFactory.initElements(driver, Login.class);


Question #32 : What is Object Repository? How can we create an Object Repository in Selenium?

Collection of web elements belonging to Application Under Test (AUT) along with their locator values.
Whenever the element is required within the script, the locator value can be populated from the Object Repository.
Objects can be stored in an excel sheet, Page Object Class.


Question #33 : ​How can I read test data from excels?


Question #34 : ​What is a Framework?

​Its a Set of guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.


Question #35 : How to capture screenshot in WebDriver?

import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Code to copy the screenshot in the desired location
FileUtils.copyFile(scrFile, new File("C:\\failscast1.jpg"))


Question #36 : How to get the Custom attribute value?


<input id=”inputid” style=”font-size:19px”/>
<button id=”buttonid” data=”hello”>Button</button>


Question #37 : How to Drag and Drop from Ifram1 to 2?

driver.switchTo().frame(0); //Move inside to the frame.
WebElement body = driver.findElement(By.tagName("body"));;
WebElement from = driver.findElement(By.xpath("//your xpath"));
Actions act = new Actions(driver);
driver.switchTo().defaultContent(); //Move outside to the frame.

driver.switchTo().frame(1); //Move inside to another frame.
WebElement body = driver.findElement(By.tagName("body"));;
WebElement to = driver.findElement("guide_RIGHT_SAFETY_rect"));


Question #38 : ​How can we handle web-based pop-up?

​1) void dismiss() – The dismiss() method clicks on the “Cancel” button as soon as the pop up window appears.


2) void accept() – The accept() method clicks on the “Ok” button as soon as the pop up window appears.


3) String getText() – The getText() method returns the text displayed on the alert box.


4) void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.



Question #39 : What is the difference between driver.close() and driver.quit command?

close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does it return any value.

quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.


Question #40 : ​How to select value in a dropdown?

Select selectByValue = new Select(driver.findElement(“SelectID_One”)));

Select selectByVisibleText = new Select (driver.findElement(“SelectID_Two”)));

Select selectByIndex = new Select(driver.findElement(“SelectID_Three”)));


Question #41 : How to Use Selenium Expected Conditions?

Selenium WebDriver comes with a lot of expected conditions such as:

ExpectedCondition < WebElement > elementToBeClickable(By locator)

ExpectedCondition < Boolean > elementToBeSelected(By locator)

ExpectedCondition < WebElement > presenceOfElementLocated(By locator)

ExpectedCondition < Boolean > titleContains(String title)

ExpectedCondition < Boolean > titleIs(String title)

ExpectedCondition < Boolean > urlContains(String fraction)

ExpectedCondition < Boolean > urlToBe(String url)

ExpectedCondition < WebElement > visibilityOfElementLocated(By locator)

There are 2 main expected condition types that can be used with explicit waits:

WebElement searchButton = wait.until(elementToBeClickable(searchButtonXpath));;

if (!wait.until(titleContains(resultsTitle)) || !wait.until(urlContains(resultsUrl)))

throw new RuntimeException("results page is not displayed");


Question #43 : ​What are the limitations of Selenium?

  • Selenium does not support testing desktop apps or native OS features.

  • Selenium supports testing of only web based applications.

  • Captcha and Bar code readers cannot be tested using Selenium.

  • Selenium does not provide the Support of Reports. We have to use third party tools like TestNG or Junit.


Question #44 : ​When should we use Selenium Grid?

  • Selenium Grid is used to execute the test cases in different machines across different platforms
  • Selenium Grid supports Distributed test execution.


Question #45 : ​How to Test local storage of browser with Selenium?

Selenium provides the Javascript Executor functions.
You can use to get and set the local storage with this method.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“return window.localStorage.getItem('key');”


Question #46 : ​How to Handle Iframe within Iframe?

You can use the command like


Question #47 : ​How to Start a Hub and node in Selenium Grid?

Start the Hub
java -jar selenium-server-standalone-3.14.jar -role hub
Connect Node to the Hub at localhost:4444
java –jar selenium-server-standalone-3.14.jar –role node –hub http://hubIP:4444/grid/register 


Question #48 : How to Upload & Download a File using Selenium Webdriver?

WebElement uploadElement = driver.findElement("uploadfile_0"));

// enter the file path onto the file-selection input field


Question #49 : How To HandleHandling Multiple Browser Windows in Selenium WebDriver?

​Set<String> allWindows = driver.getWindowHandles();
String window1 = (String) allWindows.toArray()[0];
String window2 = (String) allWindows.toArray()[1];


Question #50 : ​How to initialize GeckoDriver and ChromeDriver?

Firefox Driver Set

Download Link :

Chrome Driver Set.

Download Link :


Question 51 : What is the difference between Page Object Model and Page Factory?

Page Object Model is a design pattern to create an Object Repository for web UI elements.
Page Factory is a built-in class in Selenium for maintaining object repository.


bonus #1 : How to upload a file in Selenium WebDriver?

WebElement uploadElement = driver.findElement("uploadfile_0"));

Selenium Java Interview Questions and Answers || That Every QA should Know - Part 1

Selenium Java Interview Questions and Answers || That Every QA should Know - Part 2

Selenium Java Interview Questions and Answers || That Every QA should Know - Part 3

Selenium Java Interview Questions and Answers || That Every QA should Know - Part 4

Are you implementing the right Test automation practices ? 
15 Best Practices and Strategies for Test Automation

👪 Join Facebook Our Community -
✅ Automation Community -
🐦Follow us on Twitter -
📖 Like us on Facebook -
🎤 Listen to our Podcast -

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.