TechBeamersTechBeamers
  • Learn ProgrammingLearn Programming
    • Python Programming
      • Python Basic
      • Python OOP
      • Python Pandas
      • Python PIP
      • Python Advanced
      • Python Selenium
    • Python Examples
    • Selenium Tutorials
      • Selenium with Java
      • Selenium with Python
    • Software Testing Tutorials
    • Java Programming
      • Java Basic
      • Java Flow Control
      • Java OOP
    • C Programming
    • Linux Commands
    • MySQL Commands
    • Agile in Software
    • AngularJS Guides
    • Android Tutorials
  • Interview PrepInterview Prep
    • SQL Interview Questions
    • Testing Interview Q&A
    • Python Interview Q&A
    • Selenium Interview Q&A
    • C Sharp Interview Q&A
    • PHP Interview Questions
    • Java Interview Questions
    • Web Development Q&A
  • Self AssessmentSelf Assessment
    • Python Test
    • Java Online Test
    • Selenium Quiz
    • Testing Quiz
    • HTML CSS Quiz
    • Shell Script Test
    • C/C++ Coding Test
Search
  • Python Multiline String
  • Python Multiline Comment
  • Python Iterate String
  • Python Dictionary
  • Python Lists
  • Python List Contains
  • Page Object Model
  • TestNG Annotations
  • Python Function Quiz
  • Python String Quiz
  • Python OOP Test
  • Java Spring Test
  • Java Collection Quiz
  • JavaScript Skill Test
  • Selenium Skill Test
  • Selenium Python Quiz
  • Shell Scripting Test
  • Latest Python Q&A
  • CSharp Coding Q&A
  • SQL Query Question
  • Top Selenium Q&A
  • Top QA Questions
  • Latest Testing Q&A
  • REST API Questions
  • Linux Interview Q&A
  • Shell Script Questions
© 2024 TechBeamers. All Rights Reserved.
Reading: 35 Selenium Webdriver Questions for Interview
Font ResizerAa
TechBeamersTechBeamers
Font ResizerAa
  • Python
  • SQL
  • C
  • Java
  • Testing
  • Selenium
  • Agile Concepts Simplified
  • Linux
  • MySQL
  • Python Quizzes
  • Java Quiz
  • Testing Quiz
  • Shell Script Quiz
  • WebDev Interview
  • Python Basic
  • Python Examples
  • Python Advanced
  • Python OOP
  • Python Selenium
  • General Tech
Search
  • Programming Tutorials
    • Python Tutorial
    • Python Examples
    • Java Tutorial
    • C Tutorial
    • MySQL Tutorial
    • Selenium Tutorial
    • Testing Tutorial
  • Top Interview Q&A
    • SQL Interview
    • Web Dev Interview
  • Best Coding Quiz
    • Python Quizzes
    • Java Quiz
    • Testing Quiz
    • ShellScript Quiz
Follow US
© 2024 TechBeamers. All Rights Reserved.
Selenium Interview

35 Selenium Webdriver Questions for Interview

Last updated: Feb 24, 2024 9:38 pm
By Meenakshi Agarwal
Share
15 Min Read
35 Selenium Webdriver Questions for Automation Testers
35 Selenium Webdriver Questions.
SHARE

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.

Contents
Core Concept Related Selenium Webdriver Questions.Q: How many types of Webdriver APIs are available in Selenium?Q: How would you make sure that a page is loaded using Selenium and Webdriver?Q: How to launch a batch file in a Selenium Webdriver project?Q: How do you read a JavaScript variable in Selenium WebDriver?Q: How to run the Selenium IDE test suite from the command line?Q: How to run the Selenium Webdriver test from the command line?Q: What are the different exceptions you face in Selenium Webdriver?Q: How would you automatically click a screenshot whenever an exception occurs?Q: How would you select any particular text using the Selenium Webdriver?Q: Give an example to perform drag and drop action In Selenium WebDriver.Q: How would you fill a text field without calling the sendKeys()?Q: How can you check the state of a checkbox/radio button?Q: How would you handle the alert popups in Selenium Webdriver?Q: What is the process to start the IE/Chrome browser?Q: How would you simulate the right-click operation in WebDriver?Q: How would you select a menu item from a drop-down menu?Q: What is the FirefoxDriver, class, or interface? And which interface does it implement?Q: What is the name of the super interface of the Webdriver?Q: What is the main difference between the close() and quit() methods?Q: What is the best way to check for the highlighted text on a web page?Q: How would you use a Selenium variable say “size” from the JavaScript?Q: What is the Selenese command to show the value of a variable in the log file?CSS/XPath Related Selenium Webdriver Questions.Q: How would you differentiate between the absolute and relative XPath?Q: What are the different ways to find the element by CSS class?Q: How to specify a child element using XPath?Q: How to specify a child element using CSS?Q: How to identify a sub-child element using XPath?Q: How to identify a sub-child element using CSS?Q: How do you access an element ID using CSS?Q: How would you get to the next sibling?TestNG Selenium Webdriver Questions.Q: What is the time unit you use in TestNG time tests?Q: What is the use of priority in @Test methods and how do you set it?Q: What are the two different ways of generating reports in TestNG?Q: How to execute the TestNG test suite from the command line?Q: How to turn off the test output (generated test output folder) in TestNG?

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 effort involved in preparing the perfect set of interview questions.

We believe that this questionnaire will not only benefit in face-to-face interviews but 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.

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

35 Selenium Webdriver Questions to Crack Interviews

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 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 to select an element from the page & stand by until it becomes clickable.

selenium.waitForPageToLoad("5000");
// Or
while (!(selenium.isElementPresent("any page element ")==true)) {
  selenium.setSpeed("5");
  Thread.sleep(5);
}

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

WebDriverWait check = new WebDriverWait(driver, 100);
check.until(ExpectedConditions.anyElement(By.id(id)));

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

Ans. It’s usually in a test suite to run a batch file or an executable file for setting up the prerequisites before starting the automation. You can use the below Java code for this purpose.

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

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?

Ans. 

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

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

Ans. For this, you will have to use the <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() {

  @Override
  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 {

  eventDriver.findElement(By.id("test"));
  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.

driver.get("/");

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

Actions dummy = new Actions(driver);

dummy.doubleClick(item).build().perform();

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;

JS.executeScript("document.getElementById(User').value='admin@testmail.com'");

JS.executeScript("document.getElementById('Pass').value='######'");

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.

test.moveToElement(element).perform();

test.contextClick().perform();

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

Ans. There can be the following two situations.

  • If the menu 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 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?

Ans.

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");

System.out.println(clr);

System.out.println(bkclr);

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?

Ans.

A 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?

Ans.

//div/a

Q: How to specify a child element using CSS?

Ans.

css=div > a

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

Ans.

//div//a

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

Ans.

css=div a

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

Ans.

css=div#sample a

Q: How would you get to the next sibling?

Ans. You may try this code.

tr/td[@class='user’]/following-sibling::td

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.

@Test1(priority=0)
@Test2(priority=2)
@Test3(priority=1)

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, and passes/fails test cases.
  • 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 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 an -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 – 35 Selenium Webdriver Questions

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 a scope for 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 when you face any job interview.

Apart from interview questions, we’ve also covered a wide range of Selenium quizzes on our blog. Attempt these and refresh your concepts.

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,

TechBeamers

You Might Also Like

When Selenium Click() not Working – What to do?

TestNG Interview Questions for Sure Success in 2024

5 Most Asked Selenium Questions You Must Know

10 Selenium Technical Interview Questions and Answers.

Selenium Webdriver Howtos (10) for 2024

TAGGED:Webdriver Interview
Meenakshi Agarwal Avatar
By Meenakshi Agarwal
Follow:
Hi, I'm Meenakshi Agarwal. I have a Bachelor's degree in Computer Science and a Master's degree in Computer Applications. After spending over a decade in large MNCs, I gained extensive experience in programming, coding, software development, testing, and automation. Now, I share my knowledge through tutorials, quizzes, and interview questions on Python, Java, Selenium, SQL, and C# on my blog, TechBeamers.com.
Previous Article Difference Between Selenium IDE, Selenium RC, and Selenium Webdriver Differences in Selenium IDE, RC, Webdriver
Next Article JAVA INTERVIEW QUESTIONS EVERY SOFTWARE TESTER SHOULD KNOW Java Interview Questions for 2024

Popular Tutorials

SQL Interview Questions List
50 SQL Practice Questions for Good Results in Interview
SQL Interview Nov 01, 2016
Demo Websites You Need to Practice Selenium
7 Sites to Practice Selenium for Free in 2024
Selenium Tutorial Feb 08, 2016
SQL Exercises with Sample Table and Demo Data
SQL Exercises – Complex Queries
SQL Interview May 10, 2020
Java Coding Questions for Software Testers
15 Java Coding Questions for Testers
Selenium Tutorial Jun 17, 2016
30 Quick Python Programming Questions On List, Tuple & Dictionary
30 Python Programming Questions On List, Tuple, and Dictionary
Python Basic Python Tutorials Oct 07, 2016
//
Our tutorials are written by real people who’ve put in the time to research and test thoroughly. Whether you’re a beginner or a pro, our tutorials will guide you through everything you need to learn a programming language.

Top Coding Tips

  • PYTHON TIPS
  • PANDAS TIPSNew
  • DATA ANALYSIS TIPS
  • SELENIUM TIPS
  • C CODING TIPS
  • GDB DEBUG TIPS
  • SQL TIPS & TRICKS

Top Tutorials

  • PYTHON TUTORIAL FOR BEGINNERS
  • SELENIUM WEBDRIVER TUTORIAL
  • SELENIUM PYTHON TUTORIAL
  • SELENIUM DEMO WEBSITESHot
  • TESTNG TUTORIALS FOR BEGINNERS
  • PYTHON MULTITHREADING TUTORIAL
  • JAVA MULTITHREADING TUTORIAL

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Loading
TechBeamersTechBeamers
Follow US
© 2024 TechBeamers. All Rights Reserved.
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
  • Terms of Use
TechBeamers Newsletter - Subscribe for Latest Updates
Join Us!

Subscribe to our newsletter and never miss the latest tech tutorials, quizzes, and tips.

Loading
Zero spam, Unsubscribe at any time.
x