Skip to content

Commit

Permalink
Adding more complexity, because old IE versions don't have createNSRe…
Browse files Browse the repository at this point in the history
…solver
  • Loading branch information
barancev committed Nov 5, 2014
1 parent b7cbc37 commit 3947ebc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion javascript/atoms/locators/xpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ bot.locators.XPathResult_ = {
};


/**
* Default XPath namespace resolver.
* @private
*/
bot.locators.xpath.DEFAULT_RESOLVER_ = (function() {
var namespaces = {svg: 'http://www.w3.org/2000/svg'};
return function(prefix) {
return namespaces[prefix] || null;
};
})();


/**
* Evaluates an XPath expression using a W3 XPathEvaluator.
* @param {!(Document|Element)} node The document or element to perform the
Expand Down Expand Up @@ -118,7 +130,10 @@ bot.locators.xpath.evaluate_ = function(node, path, resultType) {
return doc.evaluate(path, node, resolver, resultType, null);
} catch (te) {
if (te.name === 'TypeError') {
return doc.evaluate(path, node, doc.createNSResolver(doc.documentElement), resultType, null);
resolver = doc.createNSResolver ?
doc.createNSResolver(doc.documentElement) :
bot.locators.xpath.DEFAULT_RESOLVER_;
return doc.evaluate(path, node, resolver, resultType, null);
} else {
throw te;
}
Expand Down

0 comments on commit 3947ebc

Please sign in to comment.