Absolute XPath |
/node1/node2 |
/html/body/div[1]/main/div/div[1]/div[1]/input[3] |
Relative XPath |
//TagName[@Attribute='Value'] |
//input[@id='email'] |
Wildcard |
//*[@Attribute='Value'] |
//*[@id='email'] |
Index |
//TagName[@Attribute='Value'][Index] |
//input[@type='text'][3] |
Contains |
//tagname[contains(@Attribute, 'Value')] |
//input[contains(@placeholder, 'First')] |
Text contains |
//tagname[contains(text(), 'Value')] |
//label[contains(text(), 'Radio')] |
Text equal |
//tagname[text()='Value'] |
//button[text()='Submit'] |
OR operator |
//TagName[@Attribute1='Value1' or @Attribute2='Value2'] |
//input[@id='email' or @placeholder='Email'] |
AND operator |
//TagName[@Attribute1='Value1' and @Attribute2='Value2'] |
//input[@id='email' and @placeholder='Email'] |
XPath chaining |
//TagName[@Attribute='Value']//TagName[@Attribute='Value'] |
//div[@id='form']//input[@id='email'] |
Following |
//TagName[@Attribute='Value']/following::TagName |
//input[@id='email']/following::input |
Following-sibling |
//TagName[@Attribute='Value']/following-sibling::TagName |
//input[@id='firstName']/following-sibling::input |
Preceding |
//TagName[@Attribute='Value']/preceding::TagName |
//input[@id='radio']/preceding::input |
Preceding-sibling |
//TagName[@Attribute='Value']/preceding-sibling::TagName |
//input[@id='email']/preceding-sibling::input |
Parent |
//TagName[@Attribute='Value']/parent::TagName |
//input[@id='email']/parent::div |
Parent |
//TagName[@Attribute='Value']/.. |
//input[@id='email']/.. |
Child |
//TagName[@Attribute='Value']/child::TagName |
//div[@id='form']/child::input[@id='email'] |
Descendant |
//TagName[@Attribute='Value']/descendant::TagName |
//div[@id='form']/descendant::input |
Ancestor |
//TagName[@Attribute='Value']/ancestor::TagName |
//input[@id='email']/ancestor::div |