Che*_*dre 2 html selenium xpath webdriver selenium-webdriver
我想从标签中获取文本,但不获取嵌套标签中的文本。183591即在下面的示例中,我只想从标签内部获取字符串并从标签中<small>排除文本。这并不简单,因为标签嵌套在标签中。这可以通过 WebDriver 和 XPath 实现吗?Service Request ID:<span><span><small>
标签中的文本每次都会发生变化。
<div id="claimInfoBox" style="background-color: transparent;">
<div class="col-md-3 rhtCol">
<div class="cib h530 cntborder">
<h4 class="no-margin-bottom">
<p>
<small style="background-color: transparent;">
<span class="text-primary" style="background-color: transparent;">Service Request ID:</span>
183591
</small>
</p>
<div class="border-bottom" style="background-color: transparent;"></div>
<div id="CIB_PersonalInfo_DisplayMode" class="cib_block">
<div id="CIB_PersonalInfo_EditMode" class="cib_block" style="display: none">
</div>
</div>
<script type="text/javascript">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
您将必须使用字符串操作。就像是:
// you will need to adjust these XPaths to suit your needs
String outside = driver.findElement(By.xpath("//small")).getText();
String inside = driver.findElement(By.xpath("//span")).getText();
String edge = outside.replace(inside, "");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9164 次 |
| 最近记录: |