QnA | How to get Xpath of simple text which is outside the HTML Tags?

How to get Xpath of simple text which is outside the HTML Tags?

Reference URL:
https://agilehelpdoc.blogspot.in/



Reference Screenshot:

HTML Code:

<div style=”text-align: Center;>

        <span id=”chapNo style=”color: #351c75;/>
        Chapter 1
</div>

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.

Extracting Xpath from HTML Code

1. Access the text directly using the Xpath. Note that, if there are multiple instances having the same HTML structure, this will return all nodes. In that case, we have to use a 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 the same HTML structure and the text specified by the developer.

//div[text()[contains(.,'Chapter 1')]]




Related Links:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:


1706total visits,3visits today

Leave a Reply

Your email address will not be published. Required fields are marked *