Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Xpath - for text without HTML tag

    <p class="result-price">
    <span>Price</span>
    $25.00 |
    <span>Member Price</span>
    $25.00
    <span>(0% discount)</span>
    </p>
    <p class="result-rating">

From the above HTML tags u can notice that the $25.00 | is just a text and is not associated with any HTML tags, I wrote the following x-path to retrieve it :

//div[contains(@data-title,'Rafael B.: Arrangement and Composition')]/div[3]/p[1]/text()[2].

and it did extract the text but in the xpath checker the result is displayed inside a container. when I use the same x-path in my script, its not retrieving the text value.

Can somebody please help.Looks like the text is inside a container/ text-area

like image 906
Marlabs mysore Avatar asked Nov 01 '25 10:11

Marlabs mysore


2 Answers

Here a way to retrieve price :

//span[text()="Price"]/following-sibling::text()[1]

or

//p[@class="result-price"]/span[1]/following-sibling::text()[1]
like image 71
Gilles Quenot Avatar answered Nov 02 '25 22:11

Gilles Quenot


Here the easiest way:

//p[contains(.,'$25.00')]

or you can find any text like below

//p[contains(.,'%replaceText%')]
like image 39
Vinit Mehta Avatar answered Nov 02 '25 22:11

Vinit Mehta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!