Selenium webdriver 获取不带标记的元素的文本
我想得到下面代码中的文本“拒绝”Selenium webdriver 获取不带标记的元素的文本,selenium-webdriver,gettext,child-nodes,Selenium Webdriver,Gettext,Child Nodes,我想得到下面代码中的文本“拒绝” <tr bgcolor="#f0f0f0"> <td class="bodyText" width="45%"> <td class="bodyText" width="55%"> <b>Status:</b> Rejected <input type="checkbox"
<tr bgcolor="#f0f0f0">
<td class="bodyText" width="45%">
<td class="bodyText" width="55%">
<b>Status:</b>
Rejected
<input type="checkbox" title="XYZ" disabled=""/>
Expired
<b>Strategy:</b>
<a href="ABC.aspx?accountID=123456&loanAppID=891011&StrategyName="/>
</td>
</tr>
以及获取子节点。但我不知道该怎么做。任何人都可以通过任何方式帮助检索文本吗?这应该可以获取包含的元素(假设在示例HTML之外没有其他类似的TDs) 一旦您获得该信息,您可以执行以下操作之一:
.getText()
并对“Status:X”执行正则表达式,其中“X”是您要查找的对象.getAttribute(“innerHTML”)
并解析HTML的这一部分。。。可能使用正则表达式要使用xpath“向上”一个节点,请使用/
//b[contains(.,'Status')]/..
感谢ans@JeffC,但也有其他TDs。到目前为止,我已经直接使用了元素的xpath,但这不是一个可靠的东西,因为它很容易改变。可能有一种方法可以排除这些。这将转到
driver.findElement(By.cssSelector("td.bodyText[width='55%']));
//b[contains(.,'Status')]/..