ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

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(“http://www.google.com/ “);

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

  • driver.get(“http://www.hubpages.com/ “);

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:
isEnabled():
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?

Command
Usage
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.
getwindowhandle()
used to get the address of the current browser
getWindowhandles()
Used to get the address of all the open browser
defaultContent()
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

working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)