0

If i try to read the text "Total Number = 533" using the following xpath //*[@id='Content'] it returns the value along with the content in the table tag also. but i just want to read the text "Total Number = 533" alone.

<div id="Content">
<h1>Suspended Accounts Report</h1>
Total Number = 533
<br>
<table>
<thead>
...........
<tbody>
..............
</table>
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 1
    Possible duplicate of [How to get text of an element in Selenium WebDriver (via the Python api) without including child element text?](http://stackoverflow.com/questions/12325454/how-to-get-text-of-an-element-in-selenium-webdriver-via-the-python-api-without) – alecxe Jan 20 '16 at 20:13

1 Answers1

0

Try below xpath

//div[@id='Content']/text()[2]

Try this to select 2nd Div

//div[2][@id='Content']/text()[2]

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • From the OP's example, "Total Number = 533" seems to be the 1st child text node of `div[@id='Content']`, not 2nd – paul trmbrth Jan 21 '16 at 09:12
  • If you see the HTML then you will find that div tag is not closed so it will take Suspended Accounts Report so expected result is in 2nd node – Shubham Jain Jan 21 '16 at 10:17
  • I get the following error when i run it on the code:org.openqa.selenium.InvalidSelectorException: The given selector //[@id='Content']/text() is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Unable to locate an element with the xpath expression //[@id='Content']/text() because of the following error: SyntaxError: The expression is not a legal expression. – Justin Sunder Chellaiah Jan 21 '16 at 14:58
  • you are using //[@id='Content']/text() while I have give xpath with //div[@id='Content']/text()[2] .. try it please – Shubham Jain Jan 22 '16 at 03:01