如何通过getText()从html中的多个子节点中提取动态文本 [英] How to extract dynamic text from multiple child nodes within the html through getText()
问题描述
我们有一个包含一些硬编码文本的 Div 和一个包含一些动态文本值的 span(请参阅下面的 HTML 代码以获得更多理解).结果文本为:1 任务从 'XYZ' 更新为 'ABC'
但是当我使用 Selenium 定位器检索时,即
final String 实际 = $("#bulk_update_confirmation").text();
那么实际只包含要更新的任务".缺少所有动态文本.
HTML代码如下(使用的浏览器是chrome)
解决方案 在尝试提取总文本之前,例如1 任务从 'XYZ' 更新为 'ABC' 您可以诱导 WebDriverWait 让所有三个子 元素都可见 并且您可以使用以下解决方案:
new WebDriverWait(driver, 10).until(ExpectedConditions.and(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='taskCountSpan']")),ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='oldStatusSpan']")),ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='newStatusSpan']"))));
We have a Div containing some hard coded text and span containing some dynamic text values (refer below HTML code for more understanding).
The resultant Text is: 1 Tasks to be updated from 'XYZ' to 'ABC'
but when I am retrieving using Selenium locator i.e.
final String actual = $("#bulk_update_confirmation").text();
Then the actual contains only "Tasks to be updated from to". All the dynamic text are missing.
HTML code is as below (browser used is chrome)
<div id="bulk_update_confirmation" class="ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 96.16px; height: auto;" scrolltop="0" scrollleft="0">
<span id="taskCountSpan">1</span> Tasks to be updated from <span id="oldStatusSpan">'XYZ'</span> to <span id="newStatusSpan">'ABC'</span> <span id="desciptionSpan"> </span> <br>
<hr>
<div class="ui-dialog-buttonset">
<button type="button" id="btn_bulk_update" onclick="updateBulkStatus()">Update</button>
<button type="button" onclick="closeBulkUpdateRequest()">Cancel</button>
</div>
</div>
解决方案 Before you attempt to extract the total text e.g. 1 Tasks to be updated from 'XYZ' to 'ABC' you can induce WebDriverWait for all the three child elements to be visible and you can use the following solution:
new WebDriverWait(driver, 10).until(ExpectedConditions.and(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='taskCountSpan']")),
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='oldStatusSpan']")),
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='newStatusSpan']"))
));
这篇关于如何通过getText()从html中的多个子节点中提取动态文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
相关文章
- 如何通过getText()从html中的多个子节点提取动态文本;
- 如何从子文本节点中提取文本 - Selenium;
- 从树节点中提取值;
- 如何从 XMLType 节点中提取元素路径?;
- 如何从pentaho中的重复节点中提取XML节点值?;
- XML Oracle:从多个重复的子节点中提取特定属性;
- xpath:使用 xpath 从节点中提取数据;
- 从多个XML文件中提取节点;
- 如何从多个“ div class”中提取文本? (html)使用R?;
- 从…标记中提取文本或直接从HTML文件中提取文本;
- XPath - 如何从一个文本节点中提取文本的特定部分;
- 从HTML Java中提取文本;
- 从HTML表中提取文本;
- 如何从HTML页面中提取文本块?;
- 从VBA中的浮点中提取位;
- 如何从父URL中的多个子URL中提取innertext?;
- 用Javascript从HTML中提取文本;
- 从文本html画布中提取路径;
- sed命令从HTML中提取文本;
- 从html文档中提取href的文本;
- 我如何使用c ++从HTML中提取文本?;
- 如何使用 Tika 从 html 中提取主要文本;
- 在Poedit中提取javascript gettext?;
- 使用 Python 从 HTML 文件中提取文本;
- 使用Python从HTML文件中提取文本;
Java开发最新文章
- Tomcat 404错误:原始服务器没有找到目标资源的当前表示,或者不愿意透露该目录的存在;
- 由于缺少ServletWebServerFactory bean,无法启动ServletWebServerApplicationContext;
- 无法反序列化的java.util.ArrayList实例出来VALUE_STRING的;
- 什么是AssertionError?在这种情况下,我应该从我自己的代码中抛出?;
- JSON反序列化投掷例外 - 无法反序列化的java.util.ArrayList实例出来START_OBJECT令牌;
- Maven构建错误 - 无法执行目标org.apache.maven.plugins:Maven的组装插件:2.5.5;
- 正确使用Optional.ifPresent();
- 获取异常(org.apache.poi.openxml4j.exception - 没有内容类型[M1.13])阅读使用Apache POI XLSX文件时?;
- SpringBoot - 制作jar文件 - 在META-INF / spring.factories中找不到自动配置类;
- HTTP状态404 - 请求的资源(/)不可用;