无法使用 RemoteWebDriver.FindElementsByXPath("/") 找到根元素; [英] Cant find root elements with RemoteWebDriver.FindElementsByXPath("/");

查看:24
本文介绍了无法使用 RemoteWebDriver.FindElementsByXPath("/") 找到根元素;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用

var element = webdriver.FindElementByXPath("/");

var elements = webdriver.FindElementsByXPath("/");

我希望获得文档的根元素.

I expect to get the root element(s) of my document.

我得到的是带有此消息的 InvalidSelectorException.

What I get instead is an InvalidSelectorException with this message.

"无效选择器:xpath表达式"/"的结果是:[objectHTML 文档].它应该是一个元素.(会话信息:chrome=50.0.2661.102)(驱动程序信息:chromedriver=2.21.371459(36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),平台=Windows NT 10.0x86_64)"

"invalid selector: The result of the xpath expression "/" is: [object HTMLDocument]. It should be an element. (Session info: chrome=50.0.2661.102) (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 10.0 x86_64)"

为什么?是否有某种方法可以获取 HTMLDocument 对象或我最初想要的根元素?

Why? Is there some way of getting that HTMLDocument object or as I initially wanted, the root element(s)?

xpath / 不是根元素(而不是文档)吗?

Isnt the xpath / the root element (instead of document)?

推荐答案

/ 引用根节点,即文档节点.并且正如方法名称所暗示的那样,它只能返回元素,而不是任意类型的节点.

/ references root node, i.e the document node. And as the method name suggests, it only capable of returning element, not arbitrary kind of node.

要获取文档的根元素,可以使用 /* 代替:

To get root element of the document, you can use /* instead :

var element = webdriver.FindElementByXPath("/*");

这篇关于无法使用 RemoteWebDriver.FindElementsByXPath("/") 找到根元素;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆