casol
casol

Reputation: 516

Selenium IDE - check if a table cell with additional html tags contains specific text?

I'm looking for a way to check if text exists in a table cell. I have no problem when there is only simple text in the cell, but my table cell has additional html tags and table. I would like to check if the url exists (foo.bar.com) and then execute some logic or move to the next row. Here is the one row snippet:

<tr bgcolor="#ffffff">
   <td align="right" valign="top" nowrap="nowrap">99</td>
   <td align="left" valign="top">
      http://foo.bar.com<br>
      <div style="margin-top: 8px"><a href="javascript:ShowTicketDetails('details_1')" style="text-decoration: none; font-weight: bold; font-size: 0.8em; color: #666666">Show Details</a></div>
      <div id="details_1" style="display: none;">
         <table class="url-tracking-details">
            <tbody>
               <tr>
                  <td align="left" valign="top" nowrap="nowrap">Product:</td>
                  <td align="left" valign="top" nowrap="nowrap">- foo <br>- bar <br>- foobar</td>
               </tr>
               <tr>
                  <td align="left" valign="top" nowrap="nowrap">Version:</td>
                  <td align="left" valign="top" nowrap="nowrap">foo 4.2</td>
               </tr>
               <tr>
                  <td align="left" valign="top" nowrap="nowrap">Categorization:</td>
                  <td align="left" valign="top" nowrap="nowrap">- bar<br></td>
               </tr>
            </tbody>
         </table>
      </div>
   </td>
   <td align="center" valign="top" nowrap="nowrap">Closed</td>
   <td align="center" valign="top" nowrap="nowrap">25/May/2022</td>
   <td align="center" valign="top" nowrap="nowrap">25/May/2022</td>
</tr>

I've tried many things, including:

store | http://foo.bar.com | url

store text | xpath=//form/table/tbody/tr[2]/td[2] | cell

execute script | if (${cell}.startsWith(${url})) { return true; } else { return false }; | x

assert | x | true

but I'm getting 'Failed: Unexpected token in JSON at position 20' enter image description here

So the full xpath for that url: /html/body/div[2]/div[3]/div[2]/div[2]/div/div/div/div[2]/div1/div/div/form/table/tbody/tr[2]/td[2]/text()

How can I catch just this text?

Upvotes: 0

Views: 650

Answers (1)

casol
casol

Reputation: 516

I got it.

store | http://foo.bar.com | url

verify element present | xpath=//form/table/tbody/tr[2]/td[2][text()='${url}']

and here is an example with conditional logic: enter image description here

the verify element present was changed to store xpath count and then assigned to the variable out (1 if true, 0 if false).

Upvotes: 0

Related Questions