<<Previous Question <<1500 Plus Interview Questions>> Next Question>>
What is an XPath, difference between Absolute and Relative XPath with examples?
Watch the answer for this Selenium Interview Question in a detailed manner in the below youtube video:
Note: Don’t forget to subscribe to my Youtube channel here: Click here
Notes used for explanation in this Youtube video are provided after the video:
Notes used in the above Youtube Video:
Technically speaking:
-
- > XPath is a language that is used for traversing through an XML document for finding the desired information.
- > Since the structure of HTML is similar to XML, we can use XPath language even to traverse through HTML tags and get the desired information.
- > XPath uses Path expressions to navigate through HTML/XML files and get the desired information.
- > ‘Path expressions’ look similar to File path. Example: /html/body/ul/li/a
Selenium Oriented way of answering this question:
- > XPath Expressions are the one of the locator types that can be used for locating the UI elements on the web pages
- > Out of all the locators, XPath Expressions are the powerful locators and can be able to locate any type of UI element.
Types of XPath Expressions:
XPath Expressions can be classified into the below two types:
Absolute XPath:
Absolute XPath tries to locate the element from the root. i.e. complete path.
Example:
- > http://compendiumdev.co.uk/selenium/basic_web_page.html
- > /html/body/p[@id=’para1′]
Relative XPath:
Unlike Absolute XPath, Relative XPath tries to locate the element directly, instead of locating from root.
Example:
- > http://compendiumdev.co.uk/selenium/basic_web_page.html
- > //p[@id=’para1′]
Next Steps:
- > For more Selenium Interview Questions and answers, continue to the next post (Click on Next Post link below)
- > Check complete Selenium Interview Questions list here (Click here)
Please leave your questions/comments/feedback below.
Happy Learning ?
<<Previous Question <<1500 Plus Interview Questions>> Next Question>>