Wednesday, July 22, 2015

Selenium WebDriver Interview Questions

Selenium WebDriver Interview Questions

1. What is Selenium WebDriver?

Selenium WebDriver is an automated testing software which is used to test web based applications. It is a freeware.

2. What are the limitations of Selenium WebDriver?

- supports web based applications.
- requires knowledge of one of the supported programming languages.
- third party tools are needed in order to generate reports.
- because its an open source tool, you may have to rely on forums or communities for any help.

3. State some of the important features of Selenium WebDriver?

The important features of WebDriver that enable the test script developer to have a better control on WebDrver and consequently on the web application that is under test:
1. Setting the desired capabilities for a browser: some of the examples of browser capabilities include enabling a browser session to support taking screenshots of the webpage, executing custom JavaScript on the webpage, enabling the browser session to interact with window alerts and so on.
2. Taking screenshots.
3. Locating target windows and iFrames: WebDriver enables the developers to switch easily between the multiple windows or frames an application loads in.
4. Exploring Navigate: WebDriver has a better control on the browser itself. Navigate, one of the WebDriver’s feature, allows the test script developer to work with the browser’s Back, Forward and Refresh controls easily.
5. Waiting for WebElements to load: Implicit wait time and Explicit wait time.
Handling Cookies: WebDriver makes handling cookies easier with getCookies(). [Selenium WebDriver Practical Guide by Satya Avasarala]
6. Selenium WebDriver supports many different browsers.
7. Selenium WebDriver supports many different languages like Java, Python, Ruby, Pearl, PHP, C# etc.

4. What are the different types of waits available in WebDriver?

Implicit wait can be beneficial where the application’s response time is inconsistent due to network speed or applications that use dynamically rendered elements with Ajax Calls.
Once set, the implicit wait is set for the life of the WebDriver instance or for the entire duration of the test. The WebDriver applies this implicit wait for all the steps that find the elements on the page unless we set it back to 0.
Explicit wait provides a better control when compared to implicit wait. Unlike an implicit wait, we can use a set of predefined or custom conditions for the script to wait for before proceeding with further steps.
An explicit wait can only be implemented in specific cases where script synchronisation is needed. [Selenium Testing Tools Cookbook By Unmesh Gundech]

Also see:
Selenium WebDriver - Wait

5. Generally which is better - Implicit wait or Explicit wait?

It is better to avoid using an implicit wait in tests and try to handle synchronisation issues with an explicit wait, which provides more control when compared to an implicit wait. [Selenium Testing Tools Cookbook By Unmesh Gundech]

6. What is difference between assert and verify commands?

Both Assert and Verify will fail the test step if the element is not found, but the Verify command will allow the test case to continue even after the test step failure. Assert on the other hand will cause the test case to stop in case of a test step failure.
If for an example you are working with a web page that has a text box on it. You must use Assert to make sure that web page has been loaded successfully, because if the web page is not loaded then there seems to be no use in continuing the test case. On the other hand Verify can be used to make sure that the text box has been loaded successfully, because if the text box has not been loaded then there is a possibility that there could be a bug, so better let the test case continue in this case.

7. What are the different types of locators in Selenium?

Locators help us to find elements on a page. In other words you can say that Selenium WebDriver uses locators to interact with elements on a web page.
An element can be located using any of the below locator types:
Locate elements using
Locate elements using By.xpath
Locate elements using
Locate elements using By.classname
Locate elements using By.cssSelector
Locate elements using By.linkText
Locate elements using By.tagName
Locate elements using By.partialLinkText

Some of the examples of locators in Java:

By tag name


8. What are the testing types that can be supported by Selenium?

Selenium supports regression and functional testing.

9. What is the difference between Selenium IDE, Selenium RC and WebDriver?


10. How to type in a textbox using Selenium?

You can use sendkeys() to enter text in a textbox. As an example please see below:
WebDriver driver = new FirefoxDriver();
WebElement e_mail = driver.findElement("email"));
Also see:
Selenium WebDriver: Verify Text Present
WebDriver: Read Text From Textbox
WebDriver: Set Focus

11. What is the difference between findElement() and findElements()?


12. How to select value in a drop-down?


13. What is the difference between driver.close() and driver.quit command?


14. How to capture screenshot in WebDriver?


15. How to click on a hyper link using linkText?

An example

Also see:
WebDriver - Click Link / Button

16. How can you find if an element in displayed on the screen?

In order to check the visibility of web elements you can use the following methods:

boolean buttonAvailable = driver.findElement(“Button_1”)).isDisplayed();

boolean ButtonEnabled = driver.findElement(“Button_1”)).isEnabled();

boolean buttonSelected = driver.findElement(“Button_1”)).isSelected();

Also see:
WebDriver - Verify Text Present

17. How can we handle pop up alerts in WebDriver?

WebDriver - Popup Alert
WebDriver - Switch to new Window

18. What are the different types of Drivers available in WebDriver?

Drivers available in Selenium WebDriver

19. What are the WebDriver browser navigation commands?

WebDriver Browser Navigation Commands.