Home > Software design >  xpath expression to find elements using conditions
xpath expression to find elements using conditions

Time:08-10

i have the following structure

<div >
    <div >
        <div >europpeen toys</div>
        <div >100</div>
    </div>
    <div >
        <div >us toys</div>
        <div >n/d</div>
    </div>
    <div >
        <div >books</div>
        <div >350</div>
    </div>
    <div >
        <div >sport</div>
        <div >0</div>
    </div>
</div>

how to write xpath expression (javascript) to select all list elements that contains

  1. a div with category class and the content should contains 'toys' keyword.
  2. and a div with price class

in this case the result should be

<div >
    <div >
        <div >europpeen toys</div>
        <div >100</div>
    </div>
</div>

thanks

CodePudding user response:

This should work

//div[contains(div[1], 'toys') and div[2][@class='price']]
  • Related