1

How to get the same result if condition:

//div[@class='lng-info']/h5[text() = 'PMP']

or condition

//div[@class='lng-info']/div[@class='price']

is true ?

How do I write a single xpath expression that combines the two above xpath and return the same elements while running the code?

1

Use | union operator. Your xpath will be:

//div[@class='lng-info']/h5[text() = 'PMP']|//div[@class='lng-info']/div[@class='price']

For example:

<div>
    <div>
        <div id="abc"/>
    </div>
    <test>
        <div id="def"/>
    </test>
</div>

xpath //div/div[@id='abc']|//test/div[@id='def'] will return

Element='<div id="abc"/>'
Element='<div id="def"/>'
0

Use following or preceding Advanced Xpath to combine the two xpath. Try this below code.

//div[@class='lng-info']/h5[text() = 'PMP']/following:://div[@class='lng-info']/div[@class='price']

//div[@class='lng-info']/h5[text() = 'PMP']/preceding:://div[@class='lng-info']/div[@class='price']
1
  • 1
    //div[@class='lng-info']/following::*[1][text() = 'PMP' or @class='price'] – STE Jun 29 '18 at 8:02
0

We avoid using Xpath in our automation scripts as it is on least priority. In our automation testing company priority we follow is id > class> name> CSS> xpath.

//div[@class='lng-info']/h5[text() = 'PMP' OR @class='price']

Thanks in advance. Please do reply if it fails to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.