Finding Text Object in Selenium

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Finding Text Object in Selenium

Selenium007
<table class="questionKeyHeader">
   <tbody>
      <tr valign="top">
         <td>
            <a>A0310C</a> = 0<br>
            <a>A2300</a> = 05/17/2018<br>
            <a>A2400B</a> = 05/12/2018<br>
            <a>A2400C</a> = --/--/----<br>
            <a>H0200C</a> = Blank/Skipped<br>
            <a>H0500</a> = 0<br>
            <a>O0100E2</a> = 0<br>
            <a>O0100F2</a> = 0<br>
            <a>O0100M2</a> = 0<br>
         </td>
      </tr>
   </tbody>
</table>
Above is the HTML this Selenium test is trying to parse. The goal is to find the text that comes after the element. The following xpath will find a given element:
.//following::table[@class="questionKeyHeader"]//td/a[text()="A2300"]

<table class="questionKeyHeader">
   <tbody>
      <tr valign="top">
         <td>
            <a>A0310C</a> = 0<br>
            <a>A2300</a> = 05/17/2018<br>
            <a>A2400B</a> = 05/12/2018<br>
            <a>A2400C</a> = --/--/----<br>
            <a>H0200C</a> = Blank/Skipped<br>
            <a>H0500</a> = 0<br>
            <a>O0100E2</a> = 0<br>
            <a>O0100F2</a> = 0<br>
            <a>O0100M2</a> = 0<br>
         </td>
      </tr>
   </tbody>
</table>

Above is the HTML this Selenium test is trying to parse. The goal is to find the text that comes after the element. The following xpath will find a given element:

.//following::table[@class="questionKeyHeader"]//td/a[text()="A2300"]

But it fails when appending /following-sibling::text() to the end of it. What is the trick to get at the text between the < a > and < br >?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/87283f2d-bd47-4236-b97f-4c9c05ccff53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Finding Text Object in Selenium

total QA
Hi,

You can use Java script executor as well. Then it might helps you.

//find the Element
String text = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].nextSibling.textContent.trim()", element);



On Friday, June 22, 2018 at 9:49:58 PM UTC+5:30, Selenium007 wrote:
<table class="questionKeyHeader">
   <tbody>
      <tr valign="top">
         <td>
            <a>A0310C</a> = 0<br>
            <a>A2300</a> = 05/17/2018<br>
            <a>A2400B</a> = 05/12/2018<br>
            <a>A2400C</a> = --/--/----<br>
            <a>H0200C</a> = Blank/Skipped<br>
            <a>H0500</a> = 0<br>
            <a>O0100E2</a> = 0<br>
            <a>O0100F2</a> = 0<br>
            <a>O0100M2</a> = 0<br>
         </td>
      </tr>
   </tbody>
</table>
Above is the HTML this Selenium test is trying to parse. The goal is to find the text that comes after the element. The following xpath will find a given element:
.//following::table[@class="questionKeyHeader"]//td/a[text()="A2300"]

<table class="questionKeyHeader">
   <tbody>
      <tr valign="top">
         <td>
            <a>A0310C</a> = 0<br>
            <a>A2300</a> = 05/17/2018<br>
            <a>A2400B</a> = 05/12/2018<br>
            <a>A2400C</a> = --/--/----<br>
            <a>H0200C</a> = Blank/Skipped<br>
            <a>H0500</a> = 0<br>
            <a>O0100E2</a> = 0<br>
            <a>O0100F2</a> = 0<br>
            <a>O0100M2</a> = 0<br>
         </td>
      </tr>
   </tbody>
</table>

Above is the HTML this Selenium test is trying to parse. The goal is to find the text that comes after the element. The following xpath will find a given element:

.//following::table[@class="questionKeyHeader"]//td/a[text()="A2300"]

But it fails when appending /following-sibling::text() to the end of it. What is the trick to get at the text between the < a > and < br >?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/cafc00f2-250c-46f4-b238-17eddfa951a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.