简体   繁体   English

在Internet Explorer中使用JavaScript和XPATH获取元素

[英]Get elements using javascript and XPATH in internet Explorer

I am writing a tool in C# which has WebBrowser in it and it uses IE 8. Now I want to write a java script which I can run on the webpage inside the WebBrowser to get some elements. 我正在用C#编写一个具有WebBrowser的工具,它使用IE8。现在,我想编写一个Java脚本,可以在WebBrowser内的网页上运行该脚本以获取一些元素。

As document.evaluate does not work on Internet Explorer, is there any other way I can achieve it? 由于document.evaluate在Internet Explorer上不起作用,还有其他方法可以实现吗? I have seen some other similar posts however they are related to writing the javascripts directly into HTML using some libraries. 我见过其他一些类似的文章,但是它们与使用某些库将javascript直接编写为HTML有关。 I am new to all this so can someone please tell me is there any way I can achieve this through the C# code? 我是这一切的新手,所以有人可以告诉我有什么方法可以通过C#代码实现吗?

Problem solved. 问题解决了。 Google's Wicked-good-xpath library worked. Google的Wicked-good-xpath库起作用了。 https://code.google.com/p/wicked-good-xpath/ https://code.google.com/p/wicked-good-xpath/

So to explain it, as its a webbrowser control, we need to add js file contents in the script tag of the current html in the WebBrowser and then call the install method as explained in your script. 因此,为了解释它,作为其Web浏览器控件,我们需要在WebBrowser中当前html的script标记中添加js文件内容,然后按照脚本中的说明调用install方法。

In case if you are shipping your javascript, then you may need to include the wicked-good-xpath libraries file contents or as per standard way ship the library with your script and add its reference in your code. 如果要运送JavaScript,则可能需要包括wicked-good-xpath库文件内容,或者按照标准方式将脚本与库一起运送并在代码中添加其引用。 (In my case I was supposed to send only one js file so added the library contents in the same file) (在我的情况下,我应该只发送一个js文件,因此将库内容添加到同一文件中)

Thanks minitech for the pointers.! 感谢minitech的指示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM