Selenium Interview Questions

Prepare for selenium interview with our comprehensive list of over 100 interview questions. These interview questions are designed for both beginners and professionals. We will start with fairly simple questions and move to the more advanced level as the post progresses.

Ques.1. What is Selenium?

Ans. Selenium is a robust test automation suite that is used for automating web based applications. It supports multiple browsers, programming languages and platforms.


Ques.2. What are different forms of selenium?

Ans. Selenium comes in four forms-

  1. Selenium WebDriver - Selenium WebDriver is used to automate web applications using browser's native methods.
  2. Selenium IDE - A firefox plugin that works on record and play back principle.
  3. Selenium RC - Selenium Remote Control(RC) is officially deprecated by selenium and it used to work on javascript to automate the web applications.
  4. Selenium Grid - Allows selenium tests to run in parallel across multiple machines.

Ques.3. What are some advantages of selenium?

Ans. Following are the advantages of selenium-

  1. Selenium is open source and free to use without any licensing cost.
  2. It supports multiple languages like Java, ruby, python etc.
  3. It supports multi browser testing.
  4. It has good amount of resources and helping community over the internet.
  5. Using selenium IDE component, non-programmers can also write automation scripts
  6. Using selenium grid component, distributed testing can be carried out on remote machines possible.

Ques.4. What are some limitations of selenium?

Ans. Following are the limitations of selenium-

  1. We cannot test desktop application using selenium.
  2. We cannot test web services using selenium.
  3. For creating robust scripts in selenium webdriver, programming langauge knowledge is required.
  4. We have to rely on external libraries and tools forperforming tasks like - logging(log4J), testing framework-(testNG, JUnit), reading from external files(POI for excels) etc.

Ques.5. Which all browsers are supported by selenium webdriver?

Ans. Some commonly used browsers supported by selenium are-

  1. Google Chrome - ChromeDriver
  2. Firefox - FireFoxDriver
  3. Internet Explorer - InternetExplorerDriver
  4. Safari - SafariDriver
  5. HtmlUnit (Headless browser) - HtmlUnitDriver
  6. Android - Selendroid/Appium
  7. IOS - ios-driver/Appium

Ques.6. Can we test APIs or web services using selenium webdriver?

Ans. No selenium webdriver uses browser's native method to automate the web applications. Since web services are headless, so we cannot automate web services using selenium webdriver.


Ques.7. What are the testing type supported by Selenium WebDriver?

Ans. Selenium webdriver can be used for performing automated functional and regression testing.


Ques.8. What are various ways of locating an element in selenium?

Ans. The different locators in selenium are-

  1. Id
  2. XPath
  3. cssSelector
  4. className
  5. tagName
  6. name
  7. linkText
  8. partialLinkText

Ques.9. What is an XPath?

Ans. Xpath or XML path is a query language for selecting nodes from XML documents. XPath is one of the locators supported by selenium webdriver.


Ques.10. What is an absolute XPath?

Ans. An absolute XPath is a way of locating an element using an XML expression beginning from root node i.e. html node in case of web pages. The main disadvantage of absolute xpath is that even with slightest change in the UI or any element the whole absolute XPath fails.
Example - html/body/div/div[2]/div/div/div/div[1]/div/input


Ques.11. What is a relative XPath?

Ans. A relative XPath is a way of locating an element using an XML expression beginning from anywhere in the HTML document. There are different ways of creating relative XPaths which are used for creating robust XPaths (unaffected by changes in other UI elements).
Example - //input[@id='username']


Ques.12. What is the difference between single slash(/) and double slash(//) in XPath?

Ans. In XPath a single slash is used for creating XPaths with absolute paths beginning from root node.
Whereas double slash is used for creating relative XPaths.


Ques.13. How can we inspect the web element attributes in order to use them in different locators?

Ans. Using Firebug or developer tools we can inspect the specific web elements.
Firebug is a plugin of firefox that provides various development tools for debugging applications. From automation perspective, firebug is used specifically for inspecting web-elements in order to use their attributes like id, class, name etc. in different locators.


Ques.14. How can we locate an element by only partially matching its attributes value in Xpath?

Ans. Using contains() method we can locate an element by partially matching its attribute's value. This is particularly helpful in the scenarios where the attributes have dynamic values with certain constant part.

xPath expression = //*[contains(@name,'user')]

The above statement will match the all the values of name attribute containing the word 'user' in them.


Ques.15. How can we locate elements using their text in XPath?

Ans. Using the text() method -

xPathExpression = //*[text()='username']

Ques.16. How can we move to parent of an element using XPath?

Ans. Using '..' expression in XPath we can move to parent of an element.


Ques.17. How can we move to nth child element using XPath?

Ans. There are two ways of navigating to the nth element using XPath-

  • Using square brackets with index position-
    Example - div[2] will find the second div element.
  • Using position()-
    Example - div[position()=3] will find the third div element.

Ques.18. What is the syntax of finding elements by class using CSS Selector?

Ans. By .className we can select all the element belonging to a particluar class e.g. '.red' will select all elements having class 'red'.


Ques.19. What is the syntax of finding elements by id using CSS Selector?

Ans. By #idValue we can select all the element belonging to a particluar class e.g. '#userId' will select the element having id - userId.


Ques.20. How can we select elements by their attribute value using CSS Selector?

Ans. Using [attribute=value] we can select all the element belonging to a particluar class e.g. '[type=small]' will select the element having attribute type of value 'small'.


Ques.21. How can we move to nth child element using css selector?

Ans. Using :nth-child(n) we can move to the nth child element e.g. div:nth-child(2) will locate 2nd div element of its parent.


Ques.22. What is fundamental difference between XPath and css selector?

Ans. The fundamental difference between XPath and css selector is using XPaths we traverse up in the document i.e. we can move to parent elements. Whereas using CSS selector we can only move downwards in the document.


Ques.23. How can we launch different browsers in selenium webdriver?

Ans. By creating an instance of driver of a particular browser-

WebDriver driver = new FirefoxDriver();

Ques.24. What is the use of driver.get("URL") and driver.navigate().to("URL") command? Is there any difference between the two?

Ans. Both driver.get("URL") and driver.navigate().to("URL") commands are used to navigate to a URL passed as parameter.
There is no difference between the two commands.


Ques.25. How can we type text in a textbox element using selenium?

Ans. Using sendKeys() method we can type text in a textbox-

WebElement searchTextBox = driver.findElement(By.id("search"));
searchTextBox.sendKeys("searchTerm");