Selenium WebDriver Interview Questions

Selenium WebDriver Interview Questions and Answers

Interview Questions and Answers on Selenium WebDriver

1) Give a detailed introduction about Selenium WebDriver?

Selenium 1 (Selenium IDE + selenium RC + Selenium Grid)

Selenium 2 (Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)

Note: Selenium WebDriver merged with Selenium 1 and called as Selenium 2.

• It is a most important tool in Selenium suite.

• It is has programming interface allows us to create and execute Test cases against different browsers (ex: Firefox, IE, Google Chrome etc…)

• WebDriver supports various programming languages(Java, .Net, PHP, Perl, Python and Ruby) to enhance Test cases.

• WebDriver supports various operating environments (MS Windows, UNIX and Macintosh etc…) to create and execute Test cases.

• WebDriver supports Data Driven testing, Cross browser testing.

• Webdriver is faster than other tools in Selenium suite.

• WebDriver supports Parallel test execution with the help of TestNG.

• WebDriver doesn’t have IDE, only Programming interface.

• WebDriver doesn’t have built in Result reporting facility, it provides summary only.
(* with the help of TestNG we can generate HTML test reports.)

• No object Repository in selenium WebDriver (This limitation is for entire Suite), so no centralized maintenance of Objects).

• Using Element locators, Webdriver methods and Java programming features we can createand execute Test cases.

2) How to set up Selenium WebDriver Environment?

• Download and install Java (JDK) software – to enhance test cases using Java programming features.

• Set Path environment variable- to access Java from any directory.

• Download Eclipe IDE and extract

• Download WebDriver Java Language binding and add Webdriver jar files (in Eclipse)

• Install Firebug and FirePath plug ins for Mozilla Firefox browser to inspect Elements.

Note: For Internet Explorer and Google chrome, no need to install any plug ins, They have built in Developer tools.
Note 2: Element locators and WebDriver methods are common for all browsers, browser driver only varies from one browser to another.
Note 3: Firefox driver is default driver in Webdriver, For IE and Chrome we need to download drivers.

Download Selenium WebDriver Java binding from website and extract.

Navigation for adding Webdriver jar files in Eclipse.

Create Java project in Eclipse

> Select src and right click

> Build path

> Configure Build Path

> select Libraries tab

> Click “Add External JARs

> Browser path of the WebDriver jars

> Add

3) How to create Test cases using Selenium WebDriver?

• Using Element locators, WebDriver methods and Java programming features we can create Test cases.

• Element locators for recognizing objects/elements.

• WebDriver Methods are used perform operatopns on Elements or objects.

• Java Programming for enhancting Test cases.

4) What are the Testing frameworks support Selenium WebDriver with Java?



We can use either JUnit or TestNG testing framework with Java and Webdriver

5) What are the Element Locators that Selenium WebDriver supports to recognize Elements?

Selenium Webdriver supports 8 Element locators to recognize Objects/Elements.

i) id

ii) name

iii) className

iv) tagName

v) linkText

vi) partialLinkText

vii) cssSelector

viii) xpath

Note: We can use any one unique locator to recognize the Object/Element.

6) What is Cross Browser Testing?

Testing web applications using multiple browsers, Cross browser testing involves checking compatibility of the application.

7) How to conduct Cross Browser Testing using WebDriver?

• Using Browser Drivers we can conduct Cross browser testing.

• For Mozilla Firefox, we no need to download the browser driver.

• For IE and Chrome etc… browsers download the browser drivers and set path.

Create Browser Driver Object for Mozilla Firefox:

WebDriver driver = new FirefoxDriver();

Create Browser Driver Object for Internet Explorer:

System.setProperty(“”, “E:/IEDriverServer.exe”);
WebDriver driver = new InternetExplorerDriver();

Create Browser Driver Object for Google Chrome:

System.setProperty(“”, “E:/chromedriver.exe”);
WebDriver driver = new ChromeDriver();

8) What are the important operations on Browser object?

Operation: Open URL
WebDriver code: driver.get(“http:/”);

Operation: Return Browser Title
WebDriver code: String s = driver.getTitle();

Operation: Return Current URL
WebDriver code: String s = driver.getCurrentUrl();

Operation: Close focused Browser
WebDriver code: driver.close

Operation: Close all Browsers that opened by WebDriver
WebDriver code: driver.quit

9) What are the Elements/Objects in Web Applications?

Image, Image Link, Image Button
Text box
Edit Box
Text Area
Check box
Radio Button
Drop down box
List box
Combo box
Web table /HTML table

10) Write a Test case using Selenium WebDriver?

Manual Test Case:

Test Case Name: Admin Login


i) Launch the Browser and navigate to www.gcrit/build3/admin/

ii) Enter user name

iii) Enter Password

iv) Click Login button

Verification point:
Check the existance of “Logoff” link, if exists then pass otherwise fail

Selenium Test Case:

WebDriver driver = new FirefoxDriver();

if (driver.findElement(By.linkText(“Logoff”)).isDisplayed()){
System.out.println(“Login Successful”);
else {
System.out.println(“Login Failed”);

11) How to conduct Batch Testing using WebDriver?

Using TestNG Annotations we can group Test cases and execute series of Test cases.

12) How to handle Link Element?

Operation: Click Link
WebDriver code: driver.findElement(By.linkText(“Gmail”)).click();

Operation: Check the link existance
WebDriver code:
boolean a = driver.findElement(By.xpath(“.//*[@id=’gbw’]/div/div/div[1]/div[1]/a”)).isDisplayed();
System.out.println(a); //true

Operation: Check the link enabled status
WebDriver code:
boolean b = driver.findElement(By.xpath(“.//*[@id=’gbw’]/div/div/div[1]/div[1]/a”)).isEnabled();
System.out.println(b); //true

Operation: Return the Link Name
WebDriver code:
String c = driver.findElement(By.xpath(“.//*[@id=’gbw’]/div/div/div[1]/div[1]/a”)).getText();
System.out.println(c); //Gmail

13) How to handle Button element?

Important operations on Buttons:
Enabled status

Display status


Return name of the Button

type of the object


public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
WebElement button = driver.findElement(“next”));
boolean a = button.isDisplayed();
boolean b = button.isEnabled();

14) How to handle Edit box element?

Important Operations on Edit box:
Enter a Value,

Clear the Value,

Check enabled status,

Check edit box existence,

Get the value etc…
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
//Enter a Value

//Return the Value
String value = driver.findElement(“Email”)).getAttribute(“name”);

//Return Type of the Object
String value2 = driver.findElement(“Email”)).getAttribute(“type”);

//Return display status
boolean a = driver.findElement(“Email”)).isDisplayed();

//Return Enabled status
boolean b = driver.findElement(“Email”)).isEnabled();

// Clear the Value

15) How to handle Images?

Three types of Image elements in Web Environment
1) General Image (No functionality)

2) Image Button (Submits)

3) Image Link (Redirects to another page/location)

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String Title = driver.findElement(“hplogo”)).getAttribute(“Title”);



16) How to handle Radio Button element?

Operations on Radio Button
i) Select Radio Button

ii) Verify if the Radio Button is Displayed or not?

iii) Verify if the Radio Button is enabled or not?

iv) Verify if the Radio Button is Selected or not?
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
boolean a = driver.findElement(By.xpath(“.//*[@id=’bodyContent’]/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]”)).isDisplayed();
System.out.println(a); //true

boolean b = driver.findElement(By.xpath(“.//*[@id=’bodyContent’]/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]”)).isEnabled();
System.out.println(b); //true

boolean c = driver.findElement(By.xpath(“.//*[@id=’bodyContent’]/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]”)).isSelected();
System.out.println(c); //false


boolean d = driver.findElement(By.xpath(“.//*[@id=’bodyContent’]/form/div/div[2]/table/tbody/tr[1]/td[2]/input[1]”)).isSelected();
System.out.println(d); //true


17) How to handle Check box element?

Operations on Check box
i) Check if the check box is displayed or not?

ii) Check if the check box is enabled or not?

iii) Check if the check box is Selected or not?

iv) Select the Check box

v) Unselect the Check box


public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();

boolean display = driver.findElement(By.xpath(“html/body/input[2]”)).isDisplayed();
System.out.println(“Displayed Status: ” + display);

boolean enabled = driver.findElement(By.xpath(“html/body/input[2]”)).isEnabled();
System.out.println(“Enabled Status: ” + enabled);

boolean check = driver.findElement(By.xpath(“html/body/input[2]”)).isSelected();
System.out.println(“Check Status: ” + check);


boolean check2 = driver.findElement(By.xpath(“html/body/input[2]”)).isSelected();
System.out.println(“Check Status: ” + check2);


boolean check3 = driver.findElement(By.xpath(“html/body/input[2]”)).isSelected();
System.out.println(“Check Status: ” + check3);


18) How to handle Frames?

• HTML frames are used to divide our Browser window into multiple sections,
where each section can load a separate html document.

• Frames are sections of Web page displayed on top window.

• Whenever we access the page then focus is on the top window.

Switch to a frame is done in two ways:

i) Using frame index

driver.switchTo.frame(int index);

ii) Using frame name

driver.switchTo.frame(String name);

//Using Frame index

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
//Using Frame name

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
Switch from a frame to Top window:


public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();

//Switch from Top window to 3rd frame
//Switch from 3rd frame to Top window
//Switch from Top window to 1st frame

19) How to handle Web Table?

Important Operations on Web Table:
Get cell value

Rows Count

Cells Count

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();

String s = driver.findElement(By.xpath(“.//*[@id=’students’]/tbody/tr[2]/td[2]”)).getText();

WebElement htmlTable = driver.findElement(“students”));

List <WebElement> rows = htmlTable.findElements(By.tagName(“tr”));
int i = rows.size();

List <WebElement> cells = htmlTable.findElements(By.tagName(“td”));
int j = cells.size();

20) How to handle Multiple Browsers?

We can Handle Multiple Browsers using Browser window handle.

21) How to handle duplicate elements/objects?

We can Handle duplicate objects/elements using index, index starts from 0 to 9 and Top left of the web page to Bottom right.


You may also like...

Leave a Reply