Robot Framework - validating text from mouse pointer

Viewed 5264

My issue is that there are some tooltips with help text. When the mouse is moved over the tooltip, some help text appears as shown in the picture. In the previous iterations I used the following code to validate the text which worked perfectly. But its not working anymore now in the new version of the webpage.

Thanks for your support

${helpText} set Variable    (Optional) Please enter any additional information about this sample 
Mouse over  ${Tooltip}  
Wait Until Page Contains    ${helpText} 5s

enter image description here

<a href="#" data-toggle="tooltip" title="(Optional) Please enter any additional information about this sample">
                                            <i class="fa fa-question-circle" aria-hidden="true"></i></a>

UPDATE

I am actually able to validate the tooltip comments in some cases, but found that the tooltip attribute was not "Title", but "data-original-title". When the html code is written like the following, the test passes:

<a href="#" data-toggle="tooltip" title="" data-original-title="(Required) Please enter the legal first name">
      <i class="fa fa-question-circle" aria-hidden="true"></i>
        </a>

Difference is when the Title attribute is straightforward like my first example, the test fails. But in cases, where the data-original-title attribute is used, the test passes.

1 Answers

As you can see from the attached html source, the tooltip text is usually in the title attribute of the element (in a more fancy UI framework it might be in a separate element - to allow formatting etc, that's shown through js on mouse over; but that's not the case here).

So in order to validate it, you should get the attribute value and compare; e.g.:

${locator}=      Set Variable    xpath=//a[@data-toggle="tooltip"]    # this is NOT a good locator - but can't think of a better one with the provided source
${the tooltip}=  Get Element Attribute    ${locator}@title   # after the @ you specify the name of the target attribute - title in this case

Should Contain   ${the tooltip}     (Optional) Please enter    # any text validation you need happens here
Related