Monday, May 9, 2011

XPath Selectors in IE7 for Selenium....

Apparently IE7 does not have a native XPath selector engine, so Selenium relies on the JavaScript
open-source version http://coderepos.org/share/wiki/JavaScript-XPath. You can confirm by unpackaging the Selenium server code (selenium-server-standalone-2.0b3) and dig through the core/xpath directory to confirm this point.

Suppose you have this DIV tag:

<input myAttr="hey"/>

And you want to use XPath selectors to find the appropriate attribute:
sel.click("//input[@myattr=%s]" % (id_selected))
sel.click("//input[@myAttr=%s]" % (id_selected))

You can look through all the possible XPath combinations by looking through the test code:
http://svn.coderepos.org/share/lang/javascript/javascript-xpath/trunk/test/functional/index.html

The JavaScript code also has a PathExpr.parse() function that does filter expression matching and parsing.

No comments:

Post a Comment