如何使用 Selenium Java 2.8 获取当前 DOM?
我正在使用最新版本的 Selenium 和 chromedriver 来测试 ZK 应用程序。
在测试期间,我想转储 DOM(或其一部分)来帮助我找到所需的元素(并且可能帮助必须维护测试的人)。
WebDriver.getPageSource()
方法看起来很有前途,但它只返回服务器发送的 HTML,而不是运行所有 JavaScript 代码后的结果。
JavaScript 代码被运行;我可以通过 ID 找到在 getPageSource()
的输出中看不到的元素。所以我尝试了 WebElement.getText()
但这只是元素的文本,而不是元素本身或其属性。
是否有可能获得 DOM 还是我必须在这里进行锁孔手术?
I'm using the latest version of Selenium and the chromedriver
to test a ZK application.
During the test, I'd like to dump the DOM (or part of it) to help me find the elements I need (and probably help people who have to maintain the test).
The method WebDriver.getPageSource()
looked promising but it only returns the HTML as it was sent by the server, not the result after running all the JavaScript code.
The JavaScript code is run; I can find elements by ID that I can't see in the output of getPageSource()
. So I tried WebElement.getText()
but that is only the text of the elements, not the elements themselves or their attributes.
Is it possible at all to get the DOM or do I have to do keyhole surgery here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确实有同样的问题,但我发现做到这一点的唯一方法是 ExecuteScript:
为什么 By 不支持 By.DOM 的功能我真的不知道......我怀疑它是由于需要网络驱动程序对于多个浏览器等
I have the same question really but the only way I've found to do it is ExecuteScript:
why the By doesnt support By.DOM with a function I don't really know...I suspect its due to the need for a webdriver for multiple browsers etc