我是靠谱客的博主 动听翅膀,最近开发中收集的这篇文章主要介绍java如何dom获取,如何使用Selenium Java 2.8获取当前的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?

解决方案

I have the same question really but the only way I've found to do it is ExecuteScript:

///

/// Gets the parentElement/Node of a particular element

///

///

///

///

public static IWebElement GetElementParent(IWebDriver driver,IWebElement element)

{

return (IWebElement) ((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].parentNode", element);

}

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

最后

以上就是动听翅膀为你收集整理的java如何dom获取,如何使用Selenium Java 2.8获取当前的DOM?的全部内容,希望文章能够帮你解决java如何dom获取,如何使用Selenium Java 2.8获取当前的DOM?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部