I used Firebug's Inspect Element to capture the XPath in a webpage, and it gave me something like:
//*[@id="Search_Fields_profile_docno_input"]
I used the Bookmarklets technique in IE to capture the XPath of the same object, and I got something like:
//INPUT[@id='Search_Fields_profile_docno_input']
Notice, the first one does not have INPUT instead has an asterisk (*). Why am I getting different XPath expressions? Does it matter which one I use for my tests like:
Selenium.Click(//*[@id="Search_Fields_profile_docno_input"]);
OR
Selenium.Click(//INPUT[@id='Search_Fields_profile_docno_input']);
*[Id=] denotes that it can be any element while the second one clearly mentions selenium to look ONLY for INPUT fields which have id as Search_Fields_profile_docno_input. The second xpath is better due to following reasons
The first one matches any element with a matching ID, whereas the second one restricts matches to <input>
elements. If these were CSS expressions it'd be the difference between #Search_Fields_profile_docno_input
and input#Search_Fields_profile_docno_input
.
Assuming you only use this ID once in your web page, the two XPaths are effectively equivalent. They'll both match the <input id="Search_Fields_profile_docno_input">
element and no other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With