I am not able to find the gettext
of the below code in the Selenium WebDriver.
<a id="551" class="blueTextNormal1 spc" onclick="sPh(this,'079');return false;" title="079">Country</a>
I want to get the value of Country. I tried using the xpath
:
driver.findElement(By.xpath("//*[@id='551']").getText())
but it is not returning any value. When I tried with
driver.findElement(By.xpath("//*[@id='551']")).getAttribute("title"))
I am getting the value as "079".
How can I to proceed?
It depends on the code as well. Give a try with the below code:
Instead of getText()
, please use getAttribute("innerHTML")
which will then return what you are looking for, including any HTML that is invisible.
<div class="no-docs-selected">
<p class="icon-alert">Please select a doc</p>
</div>
I was looking for Please select a doc
, but I didn't succeed with getText()
. But the below one worked.
driver.findElement(By.xpath("//p[@class='icon-alert']")).getAttribute("innerHTML");
I faced the same issue, and then I updated .getText() to .getAttribute("textContent") and it worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With