How to get the following text value of 50000 using xpath:
<span class="XYZ">
<span class="Value"/>
50000
</span>
I tried with
driver.findElement(By.xpath(//span[@class='xyz'])).getText()
but its not working.
How to get the following text value of 50000 using xpath:
<span class="XYZ">
<span class="Value"/>
50000
</span>
I tried with
driver.findElement(By.xpath(//span[@class='xyz'])).getText()
but its not working.
See this answer: https://stackoverflow.com/a/5455770/2386700
<span class="Value"/>
is invalid HTML. So you'll get some unexpected behavior.
Using Chrome, inspect this fiddle: https://jsfiddle.net/kqta82pd/
You'll see that Chrome automatically tries to correct the HTML for you. It removes the \>
and adds a closing </span>
tag.
So your 5000 is now contained within the <span class="Value">
element.
So the following selector should work:
driver.findElement(By.xpath(//span[@class='Value'])).getText()
Your xpath is correct but its value should be "XYZ" not "xyz" incorrect try this:
driver.findElement(By.xpath(//span[@class='xyz'])).getText()
or use
driver.findElement(By.xpath(//span[contains(text(),'50000')])).getText()
First, the /> of second span is incorrect, I think you desired shoud like this:
<span class="XYZ">
<span class="Value">30000</span>
50000
</span>
Below xpath can directly choose the 5000 from html code snippet I give out at above.
//span[@class='XYZ']/text()[contains(., '5000')]