0

I'm having problems finding the following element with this xpath //label[normalize-space(text())='F. nacimiento:'] HTML DOM The green element is the one I want to locate using the previous expression. I was able to find the red element with //label[normalize-space(text())='Servicio Decesos:'] and any other element of the same type.

I tried using //label[text()=' F. nacimiento:'] and works fine, but I'm using a loop and a the pattern //label[normalize-space(text())=' + foobar + '] to identify the rest of element.

My guess is something in that text string has a different char code to a whitespace or something like that, but I have no clue how to check that.

Is there a way to know what normalize-space is returning, in order to use it to id the element?

I have a different pattern to id the elements, but I'm pretty stubborn and this is a good chance to learn something new that could come handy in the future to solve similar issues.

I downloaded the html code as requested: Here is the red fragment

<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>

And the green fragment

<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>

1 Answers1

0

You can use the below xpath.

//label[normalize-space(.)='* F. nacimiento:']

Screenshot

enter image description here

supputuri
  • 13,644
  • 2
  • 21
  • 39
  • I can make that work with all the label elements, thanks! Would you know why my xpath was not working? And how does normalize-space(.) work? Why do I need to add the * from the span? – Carlos Castillo Apr 01 '20 at 07:24