Skip to toolbar

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:


5615total visits,11visits today

Leave a Reply

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

Site Statistics

  • Users online: 0 
  • Visitors today : 9
  • Page views today : 19
  • Total visitors : 48,395
  • Total page view: 66,587

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.