Question: How to get Xpath of simple text which is outside the HTML Tags?
Problem:
Need to extract xpaths, so that user can identify node 'Chapter 1' by using the text Chapter 1 in the xpath and without using the text Chapter 1 in the xpath.
Reference URL:
Reference Screenshot:
HTML Code:
<div style="text-align: Center;">
<span id="chapNo" style="color: #351c75;"/>
Chapter 1
</div>
Answers:
1. Access the text directlty using the Xpath. Note that, if there are multiple instances having same HTML structure, this will return all nodes. In that case we have to use loop to navigate all the nodes.//span[@id='chapNo']/following-sibling::text()
2. We can also use the on screen text 'Chapter 1' to find all the nodes with specific text. Xpath mentioned below will return all the nodes with same HTML structure and the text specified by the developer.
//div[text()[contains(.,'Chapter 1')]]
Please do comment and share the post with your friends and colleagues. For any query or question, you can also mail us at ashu.kumar940@gmail.com.
Other Blogs:
https://agilehelpdoc.blogspot.in/
Hope the given answer will help you.
ReplyDeleteThe post is very useful for extracting xpath
ReplyDeleteThanks......
DeletePlease read more posts related with Xpaths.