Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Xpath: How to search in all child elements with certain text (browser validation tool)

Options
SaskiaPega
SaskiaPega Posts: 5
edited April 2020 in SOAtest


I have a number of p elements in a div and I want to find a certain text within all of them. For some reason I can't get it to work, it finds only the first p element. Does any one know what to use differently?

Element property: I've tried both text and value here (with and without [1] )

Xpath: /descendant::div[@class="Example1"]//*
I have also tried Xpath: /descendant::div[@class="Example1"]//p

I have added a jpg because apparently I can't add this directly here as text.

Tagged:

Comments

  • tony
    tony Posts: 25 ✭✭
    Options

    Assuming this is the first instance of the text "Text to find" on you page in a P element and you are looking for exactly the phrase "Text to find," you could use an "Element properties" locator like:
    Element name: p
    Attribute name: text
    Attribute valueL Text to find

    If you prefer using an XPath, it would be:
    /descendant::p[normalize-space(.)="Text to find"]

    If you must find the text within the div, or if there might be other text within the P element to find, an XPath like the following should work:
    /descendant::div[@class="Example 1"]//p[contains(text(), "Text to find")]

    for example:
    /descendant::div[@class="Message userContent"]//p[contains(text(), "tried both")]
    will select the second paragraph in your post on this page.

  • SaskiaPega
    SaskiaPega Posts: 5
    Options

    Thank you very much! The second one worked for me.