Xpath types

 

Generic XPathExample XPath
//tagname[@attribute = 'value']//input[@id='fname']
//tagname[contains(@attribute, 'value')]//input[contains(@id, 'fname')]
//tagname[text() = 'value']//h4[text() = 'Input Box']
//tagname[contains(text(), 'value')]//h4[contains(text(), 'Input Box')]
XPath ExpressionDescriptionExample
//tagname/..Selects the parent of the specified element//span/.. — selects parent of a <span>
//tagname/following-sibling::tagnameSelects the next sibling of the specified element//label/following-sibling::input — selects <input> next to a <label>
//tagname/preceding-sibling::tagnameSelects the previous sibling of the specified element//input/preceding-sibling::label — selects <label> before an <input>