// Get all elements where pet equals cat
String xpath = "//*[@pet='cat']";// Get all elements that have the age attribute
// Get all elements where pet contains the string dog
xpath = "//*[contains(@pet,'dog')]";
xpath = "//*[@age]";
Absolute path (would break if the HTML was changed only slightly) - xpath=/html/body/form[1]
First form element in the HTML - //form[1]
The form element with attribute named ‘id’ and the value ‘loginForm’ - xpath=//form[@id='loginForm']
First input element with attribute named ‘name’ and the value ‘username’ - //input[@name='username']
First input child element of the form element with attribute named ‘id’ and the value ‘loginForm’ - //form[@id='loginForm']/input[1]
Input with attribute named ‘name’ and the value ‘continue’ and attribute named ‘type’ and the value ‘button’ - //input[@name='continue'][@type='button']
Fourth input child element of the form element with attribute named ‘id’ and value ‘loginForm’ - //form[@id='loginForm']/input[4]
No comments:
Post a Comment