我是测试新手,所以如果我的问题听起来有点初级,我提前道歉.
I am new at testing so my apologies in advance if my question sounds a bit primary.
我正在使用 Selenium 和 Java 编写测试.
I am using Selenium and Java to write a test.
我知道webElement.getAttribute("innerHTML"); 给我带来了 innerHTML,例如下面的元素:
I know that
webElement.getAttribute("innerHTML"); brings me the innerHTML, for example for the element below:
<a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" style="position: absolute; border-radius: 0px 0px 4px 4px;">
<span class="ui-icon ui-icon-closethick">close</span>
</a>
它返回:
<span class="ui-icon ui-icon-closethick">close</span>
但我需要一些能够为我带来 WebElement "a" 内部属性的东西,如下所示:
but I need something that brings me the inner attribute of WebElement "a", something like below:
href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button" style="position: absolute; border-radius: 0px 0px 4px 4px;"
如果想要元素本身的HTML,可以使用
If you want the HTML of the element itself, you can use
webElement.getAttribute("outerHTML");
它将返回元素本身的 HTML 以及所有子元素.我不确定这是否正是你想要的.我认为没有办法只获取所选元素的 HTML.
It will return the HTML of the element itself plus all the children elements. I'm not sure if that's exactly what you want. I don't think there is a way to just get the HTML of the selected element only.
这篇关于如何在 Selenium 中获取 WebElement 的 HTML 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)