Skip to content

Commit 3947ebc

Browse files
committed
Adding more complexity, because old IE versions don't have createNSResolver
1 parent b7cbc37 commit 3947ebc

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

javascript/atoms/locators/xpath.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ bot.locators.XPathResult_ = {
6262
};
6363

6464

65+
/**
66+
* Default XPath namespace resolver.
67+
* @private
68+
*/
69+
bot.locators.xpath.DEFAULT_RESOLVER_ = (function() {
70+
var namespaces = {svg: 'http://www.w3.org/2000/svg'};
71+
return function(prefix) {
72+
return namespaces[prefix] || null;
73+
};
74+
})();
75+
76+
6577
/**
6678
* Evaluates an XPath expression using a W3 XPathEvaluator.
6779
* @param {!(Document|Element)} node The document or element to perform the
@@ -118,7 +130,10 @@ bot.locators.xpath.evaluate_ = function(node, path, resultType) {
118130
return doc.evaluate(path, node, resolver, resultType, null);
119131
} catch (te) {
120132
if (te.name === 'TypeError') {
121-
return doc.evaluate(path, node, doc.createNSResolver(doc.documentElement), resultType, null);
133+
resolver = doc.createNSResolver ?
134+
doc.createNSResolver(doc.documentElement) :
135+
bot.locators.xpath.DEFAULT_RESOLVER_;
136+
return doc.evaluate(path, node, resolver, resultType, null);
122137
} else {
123138
throw te;
124139
}

0 commit comments

Comments
 (0)