Learn Java , Selenium

Generic XPath Example 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 Expression Description Example
//tagname/.. Selects the parent of the specified element //span/.. — selects parent of a <span>
//tagname/following-sibling::tagname Selects the next sibling of the specified element //label/following-sibling::input — selects <input> next to a <label>
//tagname/preceding-sibling::tagname Selects the previous sibling of the specified element //input/preceding-sibling::label — selects <label> before an <input>
Scroll to Top