Top 25 selenium interview questions


  1. Explain Asset and Verify commands in selenium?

Assert and Verify commands are used to verify the presence of an element like text, button, dropdown or link etc., in the UI.

Assert: If a particular element is not present in the UI, then the test will abort immediately.

Verify:  If a particular element is not present in the UI, then the test will not abort and it will proceed to the next steps, and it logs a failure.

  1. What is selenese?

Selenese means Selenium commands. These commands are of three types.

Actions: These are used to modify the web application state. Using actions, we can make selenium wait for a particular element, clickAndWait or hover on the dropdown.

Example for Actions in Selenium WebDriver:

package com;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;


import org.openqa.selenium.interactions.Actions;

import org.testng.Assert;

import org.testng.annotations.Test;


public class Actions_Sel {

static WebDriver driver;



public void actions() {

System.setProperty(“”, “C:\\Users\\selenium\\Downloads\\chromedriver_win32\\chromedriver.exe”);

driver=new ChromeDriver();




String expectedPageTitle=”Selenium Questions – Free Selenium Tutorials and Selenium Interview Questions”;


// Actions

Actions act=new Actions(driver);

WebElement mainMenu=driver.findElement(By.linkText(“Interview questions”));



WebElement subMenu=driver.findElement(By.linkText(“Selenium Questions”));



String actualPageTitle=driver.getTitle();


// Message displays only if assertion is false.

Assert.assertEquals(actualPageTitle, expectedPageTitle, “Assertion is false.”);







Accessors: These are used to analyze the web application state and are used to store the results in variables.


storeAllWindowTitles (varName) – Stores all window titles opened in browser and returns in the form of an array.

storeText (Elemlocator, varName) – Stores the text of any web element which has text.

storeTitle (variableName) – Stores the title of the currently opened page.

Assertions: Are of three types.

  • assert
  • verify
  • waitFor


  1. Difference between final, finally and finalize keywords?


Final is the keyword used in java to store a value which is constant (You cannot change the value).

Finally is a block in selenium to execute important test code. Finally block will always get executed even if there is an exception occurred. For example, In trycatchfinally block, exception has occurred in try block. Catch block will handle the exception and then the finally block will get executed.


package com;


import org.testng.annotations.Test;


public class Finally {



public void test_finally() {



int i=5;


System.out.println(“i value is: “+i);

}catch(Exception e){

System.out.println(“i/0 is not possible.”);


System.out.println(“finally block excuted.”);






i/0 is not possible.

finally block excuted.

Finalize() method is used for garbage collection or clean up process.

    1. Different types of locators in Selenium?

    1. Write a code to select a value from the dropdown?

  1. Difference between relative and absolute xpath?**

Ans: “/” means absolute xpath and “//” is used for relative xpath.

In absolute xpath, xpath of an element is retrieved from the root of the element. So even if a small change in the path of the element can make the test script failure.

Ex: html/body/div[1]/header/nav/ul/li[5]/ul/li[1]/a

In relative xpath, nearby id or attribute is used to generate the xpath. So the chances of element id changes are very less. Due to this reason, relative xpath is preferred over absolute xpath.

Ex: .//*[@id=’menu-item-356′]/a

Note: Install firebug and firepath addons in firefox, to generate the xpaths easily. These addons are available only in firefox browser.