Issue
I am trying to grab the text $1.00 from the following HTML code (I have the xpath, so don't worry about that). For this purpose, we can say the xpath is //*[@id="price-string"]
<strong id="price-string">$1.00</strong>
I have tried using driver.findElement(By.xpath("//*[@id="price-string"]")) followed by .gettext(), .getAttribute("textContent"), .getAttribute("innerHTML");
All of them return null, which means they could not find it.
I saw this post here on stackexchange: https://sqa.stackexchange.com/questions/30627/how-to-get-text-under-strong-tag-in-selenium-webdriver-using-java that might help. They say problem is, you cannot directly target/find text nodes with Selenium WebDriver, only regular element nodes. How would you be able to implement a fix in java? Thanks!
Solution
Try below code -
Thread.sleep(2000);
String word = driver.findElement(By.xpath("//strong[@id='price-string']")).getText();
System.out.println(word);
Note - if this is what you are looking for then please mark this as an answer.
Answered By - Swaroop Humane
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.