这里是示例 HTML 代码:
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr class="tinyfont">
<tr height="2px">
<tr height="1px">
<tr height="1px">
<tr>
<tr height="2px">
<tr height="1px">
<tr height="1px">
<tr height="2px">
</tbody>
</table>
我正在使用 selenium webdriver。 我已收到此代码中的所有子元素,但现在我想在逻辑中排除一个特定的子元素,如何从数组中排除该子元素之一。 我想排除 tr[6] 子元素..
List<WebElement> list = driver.findElements(By.xpath("/html/body/table/tbody //*"));
ArrayList<String> al1 = new ArrayList<String>();
for(WebElement ele:list){
String className = ele.getAttribute("class");
System.out.println("Class name = "+className);
al1.add(className);
}
提前致谢!!
最佳答案
忽略第 6 个表格行,然后选择所有后代:
/html/body/table/tbody/tr[position() != 6]//*
或者只选择所有不在位置 1 且具有属性的表行(然后选择它们的后代):
/html/body/table/tbody/tr[position() = 1 or @*]//*
或者更具体地说,还要检查属性名称:
/html/body/table/tbody/tr[position() = 1 or @height or @class]//*
关于java - Selenium 网络驱动程序 : exclude child node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21945377/