java - 不使用 XPath 从 webtable 内的元素获取文本(Selenium Web 驱动程序 + Java)

标签 java selenium automation automated-tests selenium-webdriver

<table class="shoppingCart" cellspacing="0" cellpadding="0" border="0" width="100%">
<thead>
<tfoot>
<tr>
<tr>
<tr>
<!-- show if promo discount applied -->
<!-- end discount -->
<tr>
<td/>
<td/>
<th scope="row" colspan="2">Order total</th>
<td class="total ajaxCart_total"> $284.96  </td>
</tr>
</tfoot>
<tbody>
</table>

有人可以帮我解决这个问题吗? 我想在运行时捕获文本 $284.96。而且我不想使用绝对 Xpath(//table/tfoot/tr[4]/td[3]) 因为页面是动态的并且 Xpath 可能经常更改。 我怎样才能做到这一点?

提前致谢, 迈克

最佳答案

如果所需 td 中提到的类是唯一的,您可以像这样使用 xpath :

//td[@class='total ajaxCart_total']

关于java - 不使用 XPath 从 webtable 内的元素获取文本(Selenium Web 驱动程序 + Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13227309/

相关文章:

java - IntelliJ 中的 Mapreduce 作业失败

python - 如何修复 Selenium WebDriverException : The browser appears to have exited before we could connect?

javascript - ReactJS Selenium 测试

python - 自动执行 Google Play 搜索列表中的项目

java - 在 Spring 测试@Scheduled

java - Android 音频环回

设计excel文件的java android错误

java - 对象实例化 - Selenium Web 驱动程序

linux - 自动化 Enter 按键不适用于 Linux Mint 15

automation - Ansible lineinfile 模块属性行未在服务器上添加环境变量