Getting value from div which contains exact string using Selenium IDE

1.1k views Asked by At

I am trying to get a value from a nested div in a web page using Selenium IDE where class names are repeated but contain unique strings, such as the structure below, but am having no luck.

<div class='ClassName'>
    <div class="col_Num">1 </div>
    <div class="col_Val">5.00 </div>
</div>

<div class='ClassName'>
    <div class="col_Num">2 </div>
    <div class="col_Val">2.00 </div>
</div>

How do I get the value of 'Col_Val' from only the div that contains "col_Num = 1"? (the value 5.00 should be returned and saved to a variable)

Thanks, J

2

There are 2 answers

0
Jsmith2800 On BEST ANSWER

From your question, it seems that you want to be able to store the column value based on the number you input. The best way to do this would be

<tr>
    <td>storeText</td>
    <td>css=div:contains("1")+[class=col_Val]</td>
    <td>value</td>
</tr>

Which will store the column value located immediately after the div containing the value you input (in this case 1)

0
Würgspaß On

In Selenium IDE enter as: Command | Target | Value

storeText | //div[@class='col_Num' and contains(text(), '1')]/following-sibling::div | value
    echo | ${value}

Output is:

[info] Executing: |storeText | //div[@class='col_Num' and contains(text(), '1')]/following-sibling::div | value |  
[info] Executing: |echo | ${value} | |  
[info] echo: 5.00  
[info] Test case passed