0

I learn JS two days, so i dont have many knowledge to resolve my problems and need help. I need to get element by xPath like a

docHTML.evaluate(elementName, docHTML.body, null, XPathResult.ANY_TYPE, null).singleNodeValue

But problem is that i need use only IE 11. I know, that IE does not supported xPath, but i could find other way, using ActionXObject.

This idea i was find on How do you run an xPath query in IE11? but i cant run this code.

I try

var doc = new ActiveXObject('Microsoft.XMLDOM'); 
doc.loadXML(window.XMLDocument); 
var node = doc.selectSingleNode('//div');
alert(node);

but didn't succeed.

Maybe I’m not getting the XML document correctly or there’s no problem?

static_cast
  • 1,174
  • 1
  • 15
  • 21
Kornext
  • 45
  • 1
  • 9
  • You can try to use the alternatives for xPath. For example, You can select an element by its ID or Selecting elements by the classes applied to them. Ref: https://hexfox.com/p/an-alternative-to-xpath-selectors/ and https://discuss.appium.io/t/alternative-for-using-find-by-xpath/12385 – Deepak-MSFT Feb 21 '19 at 05:41
  • Unfortunatly in my case i must use only xPath. :( – Kornext Feb 21 '19 at 13:12

1 Answers1

0

This code will worked with a simple pages. On google.com he returned me result ~145.

xmlDoc = new ActiveXObject("MSXML.DOMDocument");
var docHTML = window.document.documentElement;
var yourString = new XMLSerializer().serializeToString(docHTML);
xmlDoc.loadXML(yourString);
var node = xmlDoc.selectNodes('//div');
node.length

But on more dificult sites loadXML to drop down with false value.

Kornext
  • 45
  • 1
  • 9