Gold And Silver Prices
Welcome to our blog, where we explore the fascinating world of software development, software testing, Cloud management. Our aim is to provide valuable insights, tips, and techniques that will help you become a proficient in any of the technology and enhance the quality of your software projects. We cover a wide range of topics, including SDLC, STLC, ISTQB, Microsoft Azure, AWS, HubSpot.
In Selenium, there are mainly two types of XPath used for locating elements:
1. Absolute XPath:
This XPath starts from the root node and follows the complete path to the element. It is highly specific and is dependent on the structure of the HTML document.
Example: /html/body/div[1]/div[2]/div[1]/span
2. Relative XPath:
This XPath starts from any element in the HTML document (not necessarily from the root). It is more flexible and commonly used because it is less likely to break if the structure of the page changes slightly.
Example: //div[@class='example']
Additionally, XPath can be classified by the type of syntax used for selecting elements:
Attribute-based XPath: Selects elements based on their attributes (e.g., id, class, name, etc.). Example: //input[@name='username']
Text-based XPath: Selects elements based on their text content. Example: //button[text()='Submit']
Contains() function: Allows partial matching of attributes or text. Example: //a[contains(@href, 'login')]
Starts-with() function: Selects elements where an attribute value starts with a given string. Example: //a[starts-with(@href, 'http')]
And/Or operators: These are used to combine multiple conditions in XPath. Example: //input[@type='text' and @name='username']
These different approaches allow Selenium to locate elements efficiently depending on the HTML structure and requirements.
Comments
Post a Comment