gpt4 book ai didi

java - 或 selenium xpath 中的条件

转载 作者:行者123 更新时间:2023-12-02 05:45:17 25 4
gpt4 key购买 nike

如何在xpath中实现或条件以获取表td内的文本?

从下表中,我的预期输出应该是:

Black bean sauce
Black bean chicken
USA(New York)
India(New Delhi)
<小时/>
 <table>
<tr class="foods foods_s-fndds2-f41205100">
<td class="name">
<a href="Javascript://">Black bean sauce</a>
</td>
<td class="calories">280</td>
</tr>
<tr class="foods foods_s-fndds2-f41205140">
<td class="name">
<a href="Javascript://">Black bean chicken</a>
</td>
<td class="calories">280</td>
</tr>
<tr class="foods foods_s-fndds2-f41210200">
<td class="name">
<span class="truncated"><a href="Javascript://">kathmandu…</a></span>
<span class="complete"><a href="Javascript://">USA(New</a><br>
York)</span>
</td>
</tr>
<tr class="folder foods foods_undefined">
<td class="name" colspan="4"><span></span>Black, brown, or Bayo beans, dry, cooked</td>
<td class="actions"><a class="open" href="Javascript://"></a></td>
</tr>
<tr class="foods foods_s-fndds2-f41210200">
<td class="name">
<span class="truncated"><a href="Javascript://">kathmandu…</a></span>
<span class="complete"><a href="Javascript://">India(New</a><br>
Delhi)</span>
</td>
</tr>
</table>

我尝试了这个查询,但它只给出

Black bean sauce
Black bean chicken

我尝试过的代码:

   List<WebElement> folder = driver.findElements(By.xpath("//tr/td[@class='name']/a"));
for (WebElement webElement : folder) {
String foodName = webElement.getText();
System.out.println("text======" + foodName);
}

最佳答案

使用管道|选择更多节点:

//tr/td[@class='name']/a | //tr/td[@class='name']/span[@class='complete']

参见XPath or operator for different nodes

关于java - 或 selenium xpath 中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24130966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com