Question: What are the available locators in Selenium?
Answer: Available locators are mentioned below in Java:
- CSS Selector
- X Path
- Id
- Class name
- Tag name
- Name
- Link Text
Question: How user can inspect properties or attributes of any web element to utilise the same in locators?
Answer: Mainly we can use 2 major methods to inspect the properties of any web element:
- Developers Tool: User can press F12 button to open developer tool window at the bottom. Press “Ctrl+Shft+C” keys or arrow button at top left corner of developer tool window to enable inspect arrow, now click on any web element for which you want to identify the properties. User can see all the attributes of that web element under Developer tool window at the bottom.
- Firebug Plugin: It is a plugin by Firefox browser which provides various development tools for debugging the application. From test automation perspective user can inspect web elements to identify their attributes or properties in order to use them further for locating the same in automation script execution.
Question: What is “X Path”?
Answer: X Path is also known as XML path is a query language which is used for selecting nodes from XML documents. It is also a locator supported by selenium web driver.
Question: What is absolute “X Path”?
Answer: Absolute X path is the way of locating any web element using xml expression starting from the root/parent node, that means even in case of any minute change in any node property will lead to X path failure.
html/body/div/div[2]/div/div/div/div[1]/div/input
Question: What is the relative “X Path”?
Answer: Relative x path is a way of locating any web element using xml expression starting from anywhere in HTML document, that means attributes of that particular node or web element will not be dependent on its parent node for identification.
//Tag[@Attribute Name=”Attribute Value”]
Question: When we use single slash (/) and double slash (//) in X path?
Answer: We use single slash (/) for defining absolute X path and double slash (//) for defining relative X path.
Question: How we can use regular expression in defining X path when correct match of attribute is not available?
Answer: When attribute value of any web element is dynamic that means some part is static but some partial part keeps on changing then we use “Contains” method.
Leave a Reply