'On Selenium WebDriver how to get Text from div with Mark Tag
On Selenium Webdriver, how I can retrieve entire text from div with Mark Tag?
I need to verify that the word 'correctly' is present.
Example HTML code:
<div class="faq-node-body">
blah blah blah cor<mark>rec</mark>tly blah blah blah
</div>
I manage to verify the 'rec' inside the mark tag (I use java)
webElement = driver.findElement(By.xpath("//div[@class='faq-node-body' and contains(text(), 'cor')]//mark[contains(text(),rec)]"));
But my webElement is only 'rec'. Does anybody know how to check that the entire word 'correctly' is present with a mark tag on the 'rec' part of the word?
Solution 1:[1]
You can try innerHTML attribute.
String innerHTML = driver.findElement(By.xpath("//div[@class='faq-node-body']")).getAttribute("innerHTML");
This will have complete HTML text inside this locator. From there you can validate your data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ahamed Abdul Rahman |