Cheatsheet for Effective ways to use XPath in Selenium

XPath in Selenium:

  • XPath is a technique in Selenium to navigate through the HTML structure of a page. 
  • XPath enables testers to navigate through the XML structure of any document, and this can be used on both HTML and XML documents.
When to use XPath:
  • while the locators in Selenium are not enough to search elements using tags or CSS class names, then we use XPath to find the elements or to traverse the element

Benefits of XPath:
  • XPath provides an option to dynamically search for an element within a web page, thus giving sufficient flexibility to tweak a locator to one’s advantage.
Types of XPaths in Selenium:
  • Absolute Path/single slash search
    • simple but most vulnerable to minor changes in the structure of the page
    • Example: /html/body/form/p[3]/input
  • Relative Path/double slash search
    • begins with double slashes
    • Example: //form/p[3]

Popular posts from this blog

GOOGLEFINANCE attributes

Practice

Merge/join two or more video files using Python