xpath - 使用 normalize-space(text()) 找不到元素
问题描述
我在使用此 xpath //label[normalize-space(text())='F. nacimiento:']
HTML DOM查找以下元素时遇到问题
绿色元素是我想要使用前一个表达式定位的元素。我能够找到具有//label[normalize-space(text())='Servicio Decesos:']
相同类型的任何其他元素的红色元素。
我尝试使用//label[text()=' F. nacimiento:']
并且工作正常,但我使用循环和模式//label[normalize-space(text())=' + foobar + ']
来识别元素的其余部分。
我的猜测是该文本字符串中的某些内容与空格或类似内容具有不同的字符代码,但我不知道如何检查。
有没有办法知道什么 normalize-space 返回,以便用它来标识元素?
我有一个不同的模式来识别元素,但我很固执,这是一个学习新东西的好机会,将来可能会派上用场来解决类似的问题。
我按要求下载了html代码:这是红色片段
<div class="sis-frame-bg">
<table class="wideBox" align="center" cellpadding="2" cellspacing="0">
<tbody>
<tr>
<th width="20%" align="right">
<label for="DTRIES_CODZONA">
<span class="sis-important">*</span> Código postal:</label>
</th>
<td><input name="nombdato_CODZONA_1" type="text" id="DTRIES_CODZONA" size="8" maxlength="8" onblur="seccionDecesos();" value="" data-regexp="_codigoPostal" autocomplete="off"></td>
</tr>
<tr>
<th width="20%" align="right">
<label for="DTRIES_SERVICOD">
<span class="sis-important">*</span> Servicio decesos:</label>
</th>
<td>
<select name="nombdato_SERVICOD_1" id="DTRIES_SERVICOD" onchange="seccionDescricionServicio();" data-name="Servicio decesos" data-obligatorio="true" data-regexp="_cadena">
<option selected="selected" value="" title="Elegir"> Elegir</option>
</select>
</td>
</tr>
<tr>
<th colspan="2" align="left">
<div id="datosServicioDecesos">
<!-- ASI261 -->
<!-- ASI261 -->
</div>
</th>
</tr>
</tbody>
</table>
</div>
还有绿色碎片
<table class="wideBox" cellspacing="0" cellpadding="2" align="center">
<tbody>
<tr>
<th align="right">
<label for="ASEG_FECHNACI">
<span class="sis-important">*</span> F. nacimiento:</label>
</th>
<td>
<input id="ASEG_FECHNACI" name="fechnaci" type="text" maxlength="10" size="12" class="js-popUpCalendar js-dateformat hasDatepicker" onblur="formatoFecha(this);" data-name="FECHA DE NACIMIENTO ASEGURADO" data-obligatorio="true" title="" value="" data-regexp="_fecha" autocomplete="off">
<img class="ui-datepicker-trigger" src="./ico_calendar.png" alt="..." title="...">
</td>
</tr>
</tbody>
</table>
解决方案
推荐阅读
- http2 - 如何序列化 http/2 server-sent-events 连接?
- deployment - 如何使用 YAML 文件部署到 Azure Devops 中的不同环境
- python - 在谷歌浏览器中打印时,我们如何为收据打印机和条码打印机分别设置边距和缩放选项
- c# - 随着 AssemblyInfo.cs 的消失,我在哪里可以得到我的 appid?
- adobe - AEM 6.5.6 + 静态模板:如何在内置页面属性的现有字段集中添加其他字段?
- firebase - 如果路径不以斜杠 (/) 开头,Firebase 存储删除然后创建对象到路径
- html - Bootstrap 4 未正确居中
- postgresql - Postgresql 没有运行
- javascript - React 如何使用 refs 来聚焦/模糊?
- python - python - 如何根据python中训练集的均值和标准来扩展测试集?