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-
Ques.3. What are some advantages of selenium?
Ans. Following are the advantages of selenium-
Ques.4. What are some limitations of selenium?
Ans. Following are the limitations of selenium-
Ques.5. Which all browsers/drivers are supported by Selenium Webdriver?
Ans. Some commonly used browsers supported by selenium are-
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-
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/div/div/div/div/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.
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 -
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 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-
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 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.
Ques.23. How can we launch different browsers in selenium webdriver?
Ans. By creating an instance of driver of a particular browser-
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-