Selenium Interview Questions
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. know more at Selenium online training
Ques.2. What are the different forms of Selenium?
Ans. Selenium comes in four forms-
- Selenium WebDriver – Selenium WebDriver is used to automate web applications by directly calling the browser’s native methods.
- The Selenium IDE Plugin – Selenium IDE is an open-source test automation tool that works on record and playback principles.
- Selenium RC component – Selenium Remote Control(RC) is officially deprecated by Selenium and it used to work using javascript to automate the web applications.
- 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-
- Selenium is open source and free to use without any licensing cost.
- It supports multiple languages like Java, Ruby, Python, etc.
- Selenium supports multi-browser testing.
- It has vast resources and helping community over the internet.
- Using Selenium IDE component, non-programmers can also write automation scripts.
- 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-
- We cannot test desktop applications using Selenium.
- We cannot test web services using Selenium.
- For creating robust scripts in Selenium Webdriver, programming language knowledge is required.
- Also, 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-
- Google Chrome – ChromeDriver
- Firefox – FireFoxDriver
- Internet Explorer – InternetExplorerDriver
- Safari – SafariDriver
- HtmlUnit (Headless browser) – HtmlUnitDriver
- Android – Selendroid/Appium
- 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. So, there is no support for testing web services using Selenium WebDriver.
Ques.7. What are the various ways of locating an element in Selenium?
Ans. The different locators in Selenium are-
- Id
- XPath
- CSS selector
- className
- tagName
- name
- link text
- partialLinkText
Ques.8. How can we inspect the web element attributes in order to use them in different locators?
Ans. In order to locate web elements, we can use the Developer tool and plugins like Firebug.
The developer tool can be launched by pressing F12 on the browser. Users can easily hover over any element and find its different HTML properties.
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 find their attributes like id, class, name, etc. in different locators.
Ques.9. What is an XPath?
Ans. Xpath or XML path is a query language that is used for selecting nodes from XML documents. Also, it 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 the root node i.e. HTML node in the case of web pages. know more at Selenium training
The main disadvantage of absolute XPath is that even if there is a slight change in the UI or any element then also whole XPath will fail.
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, starting from anywhere in the HTML document.
In this way, there are different ways of creating robust relative XPaths that are unaffected by changes in other UI elements.
Example – //input[@id=’username’]
12. What is the difference between single slash(/) and a double slash(//) in XPath?
Ans. In XPath, a single slash is used for creating absolute XPaths, beginning from the root node. Whereas double slash is used for creating relative XPaths.
Ques.13. 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 a certain constant part.
xPath expression = //*[contains(@name,'user')]
Basically, the above statement will match all the values of the name attribute containing the word ‘user’ in them.
Ques.14. How can we locate elements using their text in XPath?
Ans. Using the text() method –
xPathExpression = //*[text()='username']
Ques.15. How can we move to the parent of an element using XPath?
Ans. Using ‘/..’ after the XPath expression of the child element, we can move to the parent of an element.
For example, the locator //div[@id=”childId”]/.. will move to the parent of the div element with id value as ‘childId’.
Ques.16. How can we move to the nth-child element using XPath?
Ans. Basically, 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.17. What is the syntax of finding elements by class using CSS Selector?
Ans. By using .className in the CSS locator, we can select all the elements belonging to a particular class e.g. ‘.red’ will select all elements having class ‘red’.
Ques.18. What is the syntax of finding elements by id using CSS Selector?
Ans. By using #idValue in the CSS locator, we can select all the elements belonging to a particular class e.g. ‘#userId’ will select the element having an id – userId. know more at Selenium online course
Ques.19. How can we select elements by their attribute value using the CSS Selector?
Ans. Using [attribute=value] in the CSS locator, 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.20. How can we move to the nth-child element using the CSS selector?
Ans. Using :nth-child(n) in the CSS locator, we can move to the nth child element e.g. div:nth-child(2) will locate 2nd div element of its parent. know more at Selenium online training from India
Ques.21. 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 the CSS selector, we can only move downwards in the document.
Comments
Post a Comment