Selenium Interview Questions And Answers

Prepare for Selenium interviews with our comprehensive list of over 100 interview questions. These questions are designed for both beginners and experienced professionals. We will start with fairly basic questions and as the post progresses, move to more tricky questions related to popular Selenium automation frameworks.

Selenium Basic Interview Questions

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 the different forms of Selenium?
Ans. Selenium comes in four forms-

  1. Selenium WebDriver – Selenium WebDriver is used to automate web applications using the browser’s native methods.
  2. Selenium IDE – A firefox plugin that works on record and playback 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 a good amount of resources and helping community over the internet.
  5. Using Selenium IDE component, non-programmers can also write automation scripts
  6. Using the selenium grid component, distributed testing can be carried out on remote machines.

Ques.4. What are some limitations of Selenium?
Ans. Following are the limitations of Selenium-

  1. We cannot test desktop applications using Selenium.
  2. We cannot test web services using Selenium.
  3. For creating robust scripts in Selenium Webdriver, programming language knowledge is required.
  4. We have to rely on external libraries and tools for performing tasks like – logging(log4J), testing framework-(TestNG, JUnit), reading from external files(POI for excels), etc.

Ques.5. Which browsers/drivers 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 the 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 is the testing type supported by Selenium WebDriver?
Ans. Selenium Webdriver can be used for performing automated functional and regression testing.

Ques.8. What are the various ways of locating an element in Selenium?
Ans. The different locators in Selenium are-

  1. Id
  2. XPath
  3. CSS selector
  4. className
  5. tagName
  6. name
  7. link text
  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 the 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 the 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 an 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 the value of its attributes in Xpath?
Ans. Using contains() method we can locate an element by partially matching its attribute’s value. This is particularly helpful in scenarios where the attributes have dynamic values with certain constant parts.

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

The above statement will match all the values of the 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 the parent of an element using XPath?
Ans. Using ‘..’ expression in XPath we can move to the parent of an element e.g. the locator //div[@id=”childId”]/.. will move to the parent of the div element with id value as ‘childId’.

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 elements belonging to a particular 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 elements belonging to a particular class e.g. ‘#userId’ will select the element having an id – userId.

Ques.20. How can we select elements by their attribute value using the CSS Selector?
Ans. Using [attribute=value] we can select all the elements belonging to a particular 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 the fundamental difference between XPath and CSS selectors?
Ans. The fundamental difference between XPath and CSS selector is using XPaths we can 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.

Selenium Java Interview Questions

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”) commands? 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 a minor difference between the two commands-

  1. driver.navigate() allows moving back and forward in browser history using driver.navigate().forward() and driver.navigate().back() commands.
  2. In the case of single-page applications (where the URL is appended by ‘#’ to navigate to different sections of the page), driver.navigate().to() navigates to a particular section by changing the URL without refreshing the page whereas driver.get() refreshes the page also.
    This refreshing of the page is also the primary reason because of which history is not maintained in case of the driver.get() command.

Source – Stack overflow

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("srch"));

Continue with the remaining questions here – Selenium Interview Questions

1 thought on “Selenium Interview Questions And Answers”

Leave a Comment