Robot Framework testing that defined headers in data-table are correct

1.4k Views Asked by At

Im having problem while testing that correct values are present inside data-table element. Im using Selenium2Library and Robot Framework 3.0 version.

Im using this code to check the values inside element

: FOR    ${item}    IN    @{elements}       INFO        console=yes
\    Wait Until Keyword Succeeds    10    1    Element Should Be Visible    
//th[contains(text(),"${item}")]    Header not found: ${item}

@{elements} is just a list of column values. It find first two column values and the last value fine when there is no more than one space between the column value. Other column values has spaces and '-' marks. I tried copying the direct value from Developer Console but it didn't help.

Element structure is:

<table class="data-table">
<thead><tr class="odd"><th class="top-left" id="col1">Number-one</th> 
<th id="col2">Second-number-column</th>
<th id="col3">Temporary number y-identification</th>
<th id="col4">Temporary numbertwo identification</th>
<th id="col5">Temporary numberthree identification</th>
<th class="top-right" id="col5">Number four</th>
</tr>
</thead>
</table>

Cant put the real column data there but its constructed like that. Problematic values are:

<th id="col3">Temporary number y-identification</th>
<th id="col4">Temporary numbertwo identification</th>
<th id="col5">Temporary numberthree identification</th>
1

There are 1 best solutions below

3
On

Try normalizing by space in xpath,

: FOR    ${item}    IN    @{elements}       INFO        console=yes
\    Wait Until Keyword Succeeds    10    1    Element Should Be Visible    
//th[contains(normalize-space(text()),"${item}")]    Header not found: ${item}