Java Selenium getAttribute是否在标记之间?

Java Selenium getAttribute是否在标记之间?,java,xpath,selenium,selenium-webdriver,Java,Xpath,Selenium,Selenium Webdriver,这就是我想用selenium验证的源代码: <tr class="myclass"> <td class="column" style="width:50%"> Key </td> <td style="width:50%"> Value </td> <td style="width:50%"> &nbsp; </td> </tr> 我做错了什么?如何获取xpath表

这就是我想用selenium验证的源代码:

<tr class="myclass">
    <td class="column" style="width:50%"> Key </td>
    <td style="width:50%"> Value </td>
    <td style="width:50%"> &nbsp; </td>
</tr>
我做错了什么?如何获取xpath表达式的文本?

在这里试试这个

driver.findElement(By.xpath("//tr[@class='myclass']/td[1]")).getText();

表中的所有列都是同级。如果不使用数组调用它们,它将返回第一个数组的值。如果td[1]不起作用,请尝试td[2]。

为什么不这样做,它不会依赖于它所处的位置,只是它存在

//tr/descendant::td[contains(text(), 'Value')]
或对以下各项进行检查:

//tr[@class='myclass']/td
然后循环遍历它们,确保“Value”出现。

尝试使用css选择器

driver.findelelement(By.cssselector(“.myclass>td[style='width:50%]”)

//tr[@class='myclass']/td