在2个tds和Selenium Java之间创建关系
我试图收集HashMap中的值-名称、数量、每千克价格和总计。我可以使用以下两项收集名称和数量在2个tds和Selenium Java之间创建关系,selenium,xpath,html-table,Selenium,Xpath,Html Table,我试图收集HashMap中的值-名称、数量、每千克价格和总计。我可以使用以下两项收集名称和数量 private By productName = By.xpath("//td//p[@class='product-name']"); private By productQuantity = By.xpath("//td//p[@class='quantity']"); 问题:当我尝试//td//p[@class='amount']时,它最终选择了4。我一直在尝试的几个选项是选择与产品名称相关的
private By productName = By.xpath("//td//p[@class='product-name']");
private By productQuantity = By.xpath("//td//p[@class='quantity']");
问题:当我尝试//td//p[@class='amount']时,它最终选择了4。我一直在尝试的几个选项是选择与产品名称相关的第二个td,这将为我提供每千克的价格//td//p[@class='product-name']/以下兄弟://td[2]
或//td//p[@class='product-name']/祖先::td
它们都没用,有什么线索可以用吗?提前感谢您抽出时间
来源:
<tr>
<td><img class="product-image" src="./images/cucumber.jpg" style="width: 50px; height: 50px;"></td>
<td>
<td>
<p class="product-name">Cucumber - 1 Kg</p>
</td>
<p class="quantity">2</p>
</td>
<td>
<p class="amount">48</p>
</td>
<td>
<p class="amount">96</p>
</td>
</tr>
黄瓜-1公斤
2
48
96
如果要获得96的值,请使用以下xpath
//td[.//p[@class='product-name']]/following::td[2]/p
或
如果要获得96的值,请使用以下
xpath
//td[.//p[@class='product-name']]/following::td[2]/p
或
这就是我需要的。谢谢这是我需要的。谢谢