Tuesday, April 1, 2014

XPath and How to use it in chrome

//input[@id="searchinput"]
//input[@id="searchinput"][@name="search"]  %two must be satisfies
//input[starts-with(@id,"search")]  %id that prefix with search
//input[substring(@id,2)=='earchInput']
//input[substring(@id,2,5)=='earch']
//title[text()='hello']  %innertext is hello
//title[normalize-space(.)='hello']  %innertext is hello, . means text
//input[contains(@id, 'hello')]  %id contains hello

//input[@id= 'hello']/following-sibling::select 
Select all <select> sibiling after <input id="hello">

following-sibling (XPath Axes) - Selects all siblings after the current node


To use XPath in Chrome
Click F12 to show the developer window
and click the following icon
to make the console open

Then type $x("your xpath here")  in the console to test the xpath

No comments:

Post a Comment