Search code examples
xpathselenium-ideassert

Selenium IDE, check (assert) if a dynamic element contains a specific text


In my website, I have a form who add a new 'td' element in a table. The content of td elements contains a random identifier

After submit, I have an html structure like that :

<table>
    <tr>
        <td class="a">edazdad</td>
        <td class="b">dscsdcsdc</td>
        ...
        <td class="n">rkjrlejf</td>
    </tr>
</table>

So, I want add an assert test in selenium IDE. I want check if my new element is in my table html element.

I try :

AssertText

  • //table/tr/td[contains(text(), 'dscsdcsdc')]::text()
  • dscsdcsdc
  • but I get the "selenium ide" error : "There were no alerts"

or

AssertText

  • //table/tr/td[contains(text(), 'dscsdcsdc')]/text()
  • dscsdcsdc
  • I get the same "selenium ide" error : "There were no alerts"

How can I do that ? =)


Solution

  • First of all something is really wrong with your Selenium IDE since assertText is acting like assertAlert. Are you sure that you are using correct command? Because the second example in you question seems totally Ok.

    Secondly if because of some strange and weird problem assertText is really not working here is the workaround:

    click | //table/tr/td[contains(text(), 'dscsdcsdc')]
    

    It will fail if there is no element with 'dscsdcsdc' because you are already verifying that element has the text by locating element containing the text.

    BUT Once again

    assertText | //table/tr/td[contains(text(), 'dscsdcsdc')]/text() | dscsdcsdc
    

    should work. Check the command please

    Good luck.