Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Tuesday, February 22, 2011

Xpath tips !!!

Get All elements :

// Get all elements where pet equals cat
String xpath = "//*[@pet='cat']";

// Get all elements where pet contains the string dog
xpath = "//*[contains(@pet,'dog')]";
// Get all elements that have the age attribute
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]
automationwithselenium.blogspot.com-Google pagerank and Worth

No comments:

Post a Comment