在网站中它有这样的页脚
<td class=resutinfo >
Displaying 1 - 10 of 41 records Results per page:
<select onchange="javascript:gotoRow(1);" name="pageSize>
<option value=10, selected="true> 10 </option>
<option value=20, > 20 </option>
<option value=10, > 30 </option>
</select>
</td>
问题:
当我使用getText()
时为此<td>
,它显示的值是这样的
Displaying 1 - 10 of 41 records Results per page: 10 20 30
但我只需要我不想要的意思,选择选项。
Displaying 1 - 10 of 41 records Results per page:
请您提供如何仅获取该字符串的建议。
最佳答案
这个想法是你得到文本 <td class="resutinfo">
首先,应该是
Displaying 1 - 10 of 41 records Results per page: 10 20 30
然后你会得到 <select>
的文本,这应该是
10 20 30
然后将其替换为空字符串以删除。
String tdText = driver.findElement(By.xpath(".//td[@class='resutinfo']")).getText();
String selectText = driver.findElement(By.xpath(".//td[@class='resutinfo']/select")).getText();
tdText.replace(selectText, "").trim();
关于java - 仅从父级 <td> 获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21770373/