ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Business and Employment»
  • Business Management & Leadership

Selenium WebDriver - The Top 10 Interview Questions And Answers

Updated on September 1, 2017
MKishor profile image

Kishor has years of working experience in software industries focusing on Agile and Project Management, A PMP & CSM certified professional.

When we talk about automation testing for a software project, there are many powerful automation tools comes to our mind. Some of them are paid tools like HP UFT, QTP, Winrunner etc., and then there are free to use tools such as Selenium, Robotium, JMeter, Cucumber etc. Each tool has its own significance in the area of their expertise. So, we have the liberty to choose the best tools based on our requirements.

Selenium web driver is one of such tool from the selenium family which is used for functional and regression testing of the web applications. It is a free to use tool with lots of features to make our automation testing more stable and secure.

Due to its remarkable features, these days many organizations are using selenium web driver over the other similar tools, thus creating many job opportunities for selenium professionals.

Let's discuss top 10 questions with answers of selenium webdriver which may help you in your interview preparation.

1. What are the great features of Selenium Webdriver?

  • The first and foremost thing is, it is an open source tool with active user communities to get the required help when needed. If you are facing any issue, then post it on the forums and get your answer in time
  • Unlike the other members of its family like Selenium RC, Selenium IDE, Webdriver directly communicates with the many well-known web browsers using its native compatibility without taking the help of any other middle software
  • Selenium webdriver is compatible with many popular web browsers such as Firefox, Chrome, Safari, Internet Explore etc., and also works on various platforms like Windows, Linux, Mac OS etc.
  • It supports many widely used programming languages such as Java, C#, Python, PHP, Pearl, Ruby etc.

There are many such user-friendly features to add to the list which makes the selenium web driver more popular among its competitors and allows it to stands out from the crowd.

2. How to launch Webdriver for popular web browsers?

It is quite easy to launch the selenium webdriver by using simple commands. For example, to launch the driver for Firefox, Chrome, and IE you need to use the following commands respectively.

  • WebDriver driver = new FirefoxDriver();
  • WebDriver driver = new ChromeDriver();
  • WebDriver driver = new InternetExplorerDriver();

There are many such commands you can use when needed. Like for mobile application testing, you can take help of IphoneDriver or AndroidDriver depending upon the OS of your device.

For example, you are working on a mobile application which runs on Android platform, so while testing the application on the Android devices you need to use the AndroidDriver. Similarly, when you have iPhone, you have to use the IPhoneDriver.

3. What are the locators in Selenium Webdriver?

For any scripting language, it is important to locate the web elements precisely. Selenium Webdriver also uses following locators to uniquely identify the web elements and makes your scripting activity fruitful.

The lists of locators are as follows:

  • ID
  • ClassName
  • Name
  • TagName
  • LinkText
  • PartialLinkText
  • XPath
  • CSS Selector
  • DOM

One interesting question you may get on XPath as, what is the difference between single slash (/) and the double slash (//).

The answer to the query is, in the case of single slash (/), the XPath selects the absolute path from the root document node or start node. While in the case of double slash (//) it selects the relative path from anywhere within the document.

4. What are the types of wait commands and where it applies?

Many automation engineers know the pain of execution failures just for silly reasons. Many times the script gets failed to execute successfully due to the insufficient time allotted to the execution of each condition. The successor condition starts executing before the previous condition is fully executed. Thus the conflict arises which resultant execution failures.

So, to deal with those situations Selenium Webdriver provides two useful options - 'Implicit Wait' and 'Explicit Wait'.

Implicit Wait
This is the default wait time that we can provide between each successive steps while creating the scripts. So, the successor condition waits for that default amount of time before it starts its execution.

For example, when the default time is 10 seconds then the system will wait for 10 seconds to complete the execution of 1st condition before moving to the 2nd condition.

A sample command is as follows:

  • driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit Wait
The default wait time - implicit Wait may not be enough in some conditions. You may get an error in such conditions which take more time to execute completely. For those conditions, Selenium web driver has another useful feature called explicit wait.

Here, you will explicitly define a certain time to complete the conditions before its successor will start executing. The system will wait for that period of time before it starts executing the next conditions.

A sample command of explicitly waiting period of 30 seconds is as follows:

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable (By.cssSelector(“#submitButton”)));

There are also options to pause the execution at any point in the script by using 'java.lang.Thread.sleep(milliseconds)' method.

For example:
To pause the execution at the certain point of the script to 10 seconds, the command will be:

  • Thread.sleep(10000);

5. What is the difference between driver.navigate() and driver.get()?

Both the commands driver.navigate() and driver.get() are used to open the URL or Webpages, but there is one difference in their execution. The driver.navigate() commands just open the web page but it won't wait till the page is completely loaded. While the driver.get() method waits until the page is completely loaded.

For example:

  • driver.navigate().to(“ “);

It opens the google homepage but won't wait till the page completely loads and moves to the next command

  • driver.get(“ “);

It will wait till the homepage of Hubpages completely loaded

There are other commands for easy navigations, such as

  • driver.navigate().forward() method //To navigate one page forward
  • driver.navigate().back() method //To move back to the previous page on the browser’s history
  • driver.navigate().refresh() method // To refresh the current page

6. What is the difference between driver.quit and driver.close() commands?

Though both the commands have the same purpose that is closing the window, but both has some differences in their functionality.

The driver.quit() method closes all the windows that are opened by the web driver. While the driver.close() command closes only the current window. It doesn't care about the other open windows. So, better take care while using these commands.If you want to close all the windows the system has opened then use the driver.quit() command, but just need to close the current one then use the driver.close() method.

Both the driver.quit() and driver.close() commands do not require any parameter to pass, and also they won't return any value.

7. What are the options to check the visibility of the web elements?

Normally, when testing a web page, you need to write the script for recognizing the web elements such as buttons, labels, drop boxes, checkboxes, radio buttons etc. So, to find such elements and checking its visibility Webdriver has some useful options such as:

  • isSelected()
  • isEnabled()
  • isDisplayed()

For Example:
boolean submitbuttonEnabled = driver.findElement(By.Name(“Submit”)).isEnabled();

8. When you require Selenium Server while working on Webdriver?

While working on Selenium Webdriver, for the majority of cases the Selenium Server is not required, unless you want to execute the test scripts on the remote machine. Also when you want to execute your scripts on the HtmlUnit driver or on multiple platforms, you require the help of Selenium Server.

For rest of the cases, your Selenium Webdriver is capable of executing the scripts by talking to the browser's native compatibility. This is one of the best features of Selenium Webdriver as it works with some of the prominent web browsers just like a real user without taking help of the selenium server or any intermediate software.

9. What are the commands you use to find and handle web elements?

find element ()
It finds the first element within the current page. Returns a single web element.
findElements ()
It finds all the elements within the current page. Returns a list of web elements.
used to get the address of the current browser
Used to get the address of all the open browser
To switch back from a frame
element.submit ()
To Submit a form

10. What is Selenium 3.0 and is there any change it brought for existing Selenium Webdriver?

Selenium 3.0 is the latest version of selenium, it is an upgrade from Selenium 2.0. And as per the changes to Selenium Webdriver is concerned, there is absolutely no change to it. You just require updating the older version without bothering the code and configurations. You won't feel any changes. Though there are some changes to the web browsers like Firefox, Chrome, Safari and IE as an improvement for the greater testing experiences.

The official release notes stated that the Selenium 3.0 has major changes to the Selenium RC API. The original selenium core implementation has been replaced with the one backed by Webdriver.

Do you agree that selenium webdriver is high on demand?

See results

© 2017 Kishor Mohanty

Please share your feedback.

    0 of 8192 characters used
    Post Comment

    No comments yet.