Home > Net >  Selenium, use Wait Until Element Is Visible with xpath Text() instead of Element Text Should Be
Selenium, use Wait Until Element Is Visible with xpath Text() instead of Element Text Should Be

Time:07-29

As RF novice, i'm trying to understand a line of code which uses "Wait Until Element Is Visible" to verify a text (string of characters) exists on the HMI page or not instead of using "Element Text Should be". In my opinion the code should be:

Element Text Should be    //*[@id="tbdyonmouseover"]/tr[1]/td[1]/span   FirstName

but the actual code uses the exact same Locator with text() in this way:

Wait Until Element Is Visible  //*[@id="tbdyonmouseover"]/tr[1]/td[1]/span[text()="FirstName"]

Are they the same? Especially when i have a table of one row with several paired data , the code uses this method extensively to check that all nodes exists (Visible?) on the page. For Example, one row with 4 paired table data td

 <tbody id="grp_801body">
   <tr>
     <td ><span  title="" style="">**doc. number**</span></td>
     <td  id="vv_8050755945013937879"><span  style="margin-left:0px;"><span >111</span></span></td>
     <td ><span  title="">**query number**</span></td>
     <td  id="vv_8050755945013937878"><span  style="margin-left:0px;"><span >**B2_G9R7_ln8**</span></span></td>
   </tr>

To check all these four tds in one place the code uses Wait instead of Element Text Should Be in the manner explained on top:

//*[@id="tbdyonmouseover"]/tr[1]/td[1]/span[text()="doc. number"]/../..//*[@id="tbdyonmouseover"]/tr[1]/td[2]/span[text()="${Dossier_Number}"]/../..//*[@id="tbdyonmouseover"]/tr[1]/td[3]/span[text()="query number"]/../..//*[@id="tbdyonmouseover"]/tr[1]/td[4]/span[text()="${myVar}"]

Is it correct especially for several nodes of a table row?

Thank you

CodePudding user response:

Yes, they are functionally the same - in the sense they will only pass if the text is the one you expect.
Still there are differences between them - obviously, the "Wait Until" will give some time for the string to appear (rendering, or js changing it) vs the immediate check of the other.

And another difference is the Element Text Should Be returns the visible text of the element - e.g. "close to what a user sees in their browser" , while the xpath with text()="FirstName" looks for a node with precisely this content - any whitespace around it or child nodes having portions of the string (not done in your example) will cause it to fail.

There is another difference - if the element is hidden, the selenium method used in Element Text Should Be will return an empty string (it's just how SE works), while the xpath will match it (as it doesn't "care" about visibility, it just parses xml). But that is not an issue with your example, the "Wait Until Element Is Visible" implies the check is on visualized elements.

  • Related