35 Selenium Webdriver Questions for Automation Testers

Software testers who are planning to get a testing or test automation job should read this post. We’ve compiled the best 35 Selenium Webdriver questions to help you succeed in a job interview. You’ll find a short and concise answer for all the Selenium Webdriver questions as most of the interviewers expect from an ideal candidate. There has been a lot of efforts involved in preparing the perfect set of interview questions.

We believe that this questionnaire will not only benefit you in face-to-face interviews also in telephonic ones as well. It has been quite popular these days as the IT companies want to make sure the technical skills of a candidate before they invite him for a one to one discussion. Also, no interviewer would ask merely the conceptual or theoretical questions; they would want to test you a bit deeper by putting up tricky questions about the technology. That’s where the list of these 35 Selenium Webdriver questions is going to help you as a supplement for cracking the interview. The readers who are interested in detailed articles may go through the core Selenium Webdriver concepts section from our blog.

In addition to this post, you should also check out the most read post on this blog which exclusively covers the core Selenium interview questions and answers for beginners and experienced. It’ll make sure that you’ve sufficient understanding of the Selenium Webdriver concepts.

35 Selenium Webdriver Questions to Succeed in a Job Interview.

35 Selenium Webdriver Questions for Automation Testers

35 Selenium Webdriver Questions.

Let’s quickly go through the list of the top Selenium Webdriver questions specially designed for testing job seekers.

Core Concept Related Selenium Webdriver Questions.

Q: How many types of Webdriver APIs are available in Selenium?

Ans. Below is the list of driver classes that you can use for the browser automation.

  • AndroidDriver,
  • ChromeDriver,
  • EventFiringWebDriver,
  • FirefoxDriver,
  • HtmlUnitDriver,
  • InternetExplorerDriver,
  • IPhoneDriver,
  • IPhoneSimulatorDriver,
  • RemoteWebDriver.


Q: How would you make sure that a page is loaded using Selenium and Webdriver?

Ans. In Selenium, you can use the below lines of code to check for the successful loading of a web page. The best approach is by selecting an element from the page & stand by till it becomes clickable.

// Or
while (!(selenium.isElementPresent("any page element ")==true)) {

Below is the Webdriver specific code to achieve the same objective.

WebDriverWait check = new WebDriverWait(driver, 100);


Q: How to launch a batch file in a Selenium Webdriver project?

Ans. It's usual in a test suite to run a batch file or an executable file for setting up the pre-requisites before starting the automation. You can use the below Java code for this purpose.

Process batch = Runtime.getRuntime.exec("path of the batch file");


Q: How do you read a JavaScript variable in Selenium WebDriver?

Ans. It's easy to access any JavaScript variable from the Selenium Webdriver test scripts. Just you need to use the below Java code snippet.

// Initialize the JS object.
JavascriptExecutor JS = (JavascriptExecutor) webdriver;
// Get the current site title.
String sitetitle = (String)JS.executeScript("return document.title");
System.out.println("My Site Title: " + sitetitle);


Q: How to run the selenium IDE test suite from the command line?

Ans. We've given the command to run the SIDE test suite in the next line.

Java -jar "C:\Selenium Webdriver Questions\selenium-server-standalone-2.33.0.jar" -htmlSuite "*firefox" "http://www.google.com" " “C:\Selenium Webdriver Questions\SeleniumSuite.HTML"


Q: How to run the Selenium Webdriver test from the command line?

Ans. We can run any Selenium Webdriver test written in Java using the following command.

java -classpath ".;selenium-server-standalone-2.33.0.jar" SampleClass


Q: What are the different exceptions you face in Selenium Webdriver?


  • WebDriverException,
  • NoAlertPresentException,
  • NoSuchWindowException,
  • NoSuchElementException,
  • TimeoutException.


Q: How would you automatically click a screenshot whenever any exception occurs?

Ans. For this you will have to use <EventFiringWebDriver> class and needs to implement the <onException> method of the <WebDriverEventListener> interface. See the code example given below.

WebDriver browser = new FirefoxDriver();

EventFiringWebDriver eventDriver = new EventFiringWebDriver(browser).register(new AbstractWebDriverEventListener() {

  public void onException(Throwable throwable, WebDriver browser) {

    // Take the screenshot using the Webdriver.
    File screen = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

    // Now you can copy the screenshot somewhere on your system.
    FileUtils.copyFile(screen, new File("c:\\Selenium Testing Questions\\screen.png"));

try {

  fail("Caught the Expected exception."); // Intentionally causing the exception for demo.

} catch (NoSuchElementException e) {

  // Triggering point for the <onException> event.


Q: How would you select any particular text using the Selenium Webdriver?

Ans. It seems an easy one at first but you need to do a little more to achieve this.


WebElement item = driver.findElement(By.xpath("//p[contains(text(),'Selenium webdriver quesions')]"));

Actions dummy = new Actions(driver);



Q: Give an example to perform drag and drop action In Selenium WebDriver?

Ans. Yes, we can use the Advanced User Interactions API to perform drag and drop operations in a Selenium Webdriver project.

Code example:

Actions act = new Actions(driver);

act.dragAndDrop(source_locator, target_locator).build().perform();

//Or you can use the below code style.

(new Actions(driver)).dragAndDrop(source_locator, target_locator).perform();


Q: How would you fill a text field without calling the sendKeys()?

Ans. It's a bit slower than the sendKeys() method but we do have means to type in a text field. See the Java code given below.

JavascriptExecutor JS = (JavascriptExecutor)webdriver;




Q: How can you check the state of a checkbox/radio button?

Ans. We can call the isSelected() method to test the status of these elements.

Example Code:

boolean test = driver.findElement(By.xpath("checkbox/radio button XPath")).isSelected();


Q: How would you handle the alert popups in Selenium Webdriver?

Ans. First, you’ve to switch the control to the pop up then press the ok or cancel button. After that, turn back to the source page screen.

Code Example:

String srcPage = driver.getWindowHandle();

Alert pop = driver.switchTo().alert(); // shift control to the alert popup.

pop.accept(); // click on ok button.

pop.dismiss(); // click on cancel button.

// Move the control back to source page.

driver.switchTo().window(srcPage);  // move back to the source page.


Q: What is the process to start the IE/Chrome browser?

Ans. If you want to start a browser then, just set the system properties as mentioned below.

// For the IE web browser.

System.setProperty("webdriver.ie.driver"," iedriver.exe file path");

WebDriver driver = new InternetExplorerDriver();

// For the Chrome web browser.

System.setProperty("webdriver.chrome.driver","chrome.exe file path");

WebDriver driver = new ChromeDriver();


Q: How would you simulate the right click operation in WebDriver?

Ans. You can make use of the Actions class features.

Actions test = new Actions(driver); // Here, driver is the object of WebDriver class.




Q: How would you select a menu item from a drop down menu?

Ans. There can be following two situations.

  • If the menu has is using the <select> tag then you can call the <selectByValue()> or <selectByIndex()> or <selectByVisibleText()> methods of the Select class.
  • If the menu doesn’t use the <select> tag then simply find the XPath of that element and perform the click action for its selection.


Q: What is the FirefoxDriver, class or an interface? And which interface does it implement?

Ans. FirefoxDriver is a Java class, and it implements the <WebDriver> interface. It contains the implementations of all the methods available in the <WebDriver> interface.


Q: What is the name of the super interface of the Webdriver?

Ans. SearchContext.


Q: What is the main difference between the close() and quit() methods?


close() - it closes the currently active browser window.

quit()- it will close all of the opened browser windows and the browser itself.


Q: What is the best way to check for the highlighted text on a web page?

Ans. Use the below code to verify the highlighted text for an element on the web page.

String clr = driver.findElement(By.xpath("//a[text()='TechBeamers']")).getCssValue("color");

String bkclr = driver.findElement(By.xpath("//a[text()='TechBeamers']")).getCssValue("background-color");




Q: How would you use a Selenium variable say "size" from the JavaScript?

Ans. ${size}


Q: What is the Selenese command to show the value of a variable in the log file?

Ans. echo()


CSS/XPath Related Selenium Webdriver Questions.

Q: How would you differentiate between the absolute and relative XPath?


Single slash "/" signifies an absolute XPath.

Double Slash "//" represents the relative XPath.


Q: What are the different ways to find the element by CSS class?

Ans. Say, the name of the CSS class is <MyTest>. Then, the most simple way to find the element is as follows.

//*[contains(@class, ‘MyTest')]

If you want an exact comparison to avoid matching texts like “OhhMyTest” or “MyTesting” then use this.

//*[contains(concat(' ', @class, ' '), ' MyTest ')]

You can even use the <normalize-space> function to remove any leading or trailing whitespaces.

//*[contains(concat(' ', normalize-space(@class), ' '), 'MyTest ')]


Q: How to specify a child element using XPath?




Q: How to specify a child element using CSS?


css=div > a


Q: How to identify a sub child element using XPath?




Q: How to identify a sub child element using CSS?


css=div a


Q: How do you access an element ID using CSS?


css=div#sample a


Q: How would you get to the next sibling?

Ans. You may try this code.


Or you can use the below code.

tr[td[@class=’user'] ='age']/td[@class='weight']


TestNG Selenium Webdriver Questions.

Q: What is the time-unit you use in testng time tests?

Ans. We use milliseconds as the time unit in @Test or @TestSuite methods.


Q: What is the use of priority in @Test methods and how do you set it?

Ans. We define the priority in @Test annotated methods to set the order of test execution. Please check the below example.


The above test will run in the following order.

Test1 => Test3 => Test2


Q: What are the two different ways of generating reports in TestNG?

Ans. There are two ways to produce a report with Test NG, they are

  • Use of Listeners: You can implement the <org.testng.ITestListener> interface and its methods. Reporting will start when the test begins, finishes, skips, passes or fails.
  • Use of Reporters: Another way to enable reporting is by implementing the <org.testng.Reporter> interface. Unlike the listener interface, here the reporting begins after the whole test suite reaches to the end. The reporting class receives the object which contains the information of the whole test run.


Q: How to execute the testng test suite from the command line?

Ans. We don't always need to open Eclipse to run the TestNG project, try using the below command instead.

java -cp “C:\Selenium Webdriver Questions\testng \lib\*;C:\Selenium Testing Questions\testng\bin” org.testng.TestNG testng.xml


Q: How to turn off the test-output (generated test output folder) in TestNG?

Ans. In Eclipse, modify the launch/Run configuration and add a <-usedefaultlisteners false> option to disable the test output.

Let’s now summarize the above post which includes the top 35 Selenium Webdriver questions and do a quick review of the content.

Final Word.

We’ve tried to bring the most pertinent Selenium Webdriver questions in this post, but this topic belongs to an evolving subject. Hence, there would always be the scope of improvements and enhancements. We’ll keep supporting all the new changes in the Selenium Webdriver technology and will add more and more questions that could add to your skills and boost your confidence while you face any job interview.

We’ve already covered a wide range of Selenium interview questions and quizzes on our blog, and this post is like a testimonial that we do introduce a fresh set of questions on a regular basis.

Next, we like you to contribute to our knowledge drive. You can do this by sharing this list of top Selenium Webdriver questions among your friends and on social media using the sharing icons shown below.


Keep Learning,