Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在2个tds和Selenium Java之间创建关系_Selenium_Xpath_Html Table - Fatal编程技术网

在2个tds和Selenium Java之间创建关系

在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。我一直在尝试的几个选项是选择与产品名称相关的

我试图收集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。我一直在尝试的几个选项是选择与产品名称相关的第二个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


这就是我需要的。谢谢这是我需要的。谢谢