How to create xpath that matches both conditions present in an element?

Description:
I need to create an Xpath that matches both the condition present in the div class = ‘item_inside’

Explanation:
Imagine There are two item_inside classes present on my webpage.
One class has Big Basket text present inside aria-label, and another class has small basket present in the aria-label tag.

//*[@class = 'item_inside']//*[@class = 'food_list']

If I write the above xpath in developer tools it shows me two results, All I want to do is to somehow add aria-label = ‘BigBasket’ in the Xpath so that it gives me a unique result.

<div class="item_inside">
 <div class="one_line">

    <div class="support_text">
        <div class="detail_info">
            <div class="headline_title_content headline_title_2" tabindex="0" aria-label="Big Basket">
            </div>
       </div>
    </div>
  </div>

  <ul _cid="123456" class="food_list">
  </ul>
</div>

Here is my tried xpath:

//*[@class = 'item_inside']//*[@class = 'one_line']//*[@class = 'headline_title_content headline_title_2' and @aria-label = 'Big Basket']//*[@class = 'item_inside' and @class = 'food_list']

Things I’ve tried:

I tried to create an Xpath with and, or , contains but I think the format of xpath was not proper so I didn’t got my output.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I suppose you need this as a first filter:

//*[@class = 'item_inside'][*[@class = 'food_list']]

So now you have every element with @class=item_inside and who has a element with class=food_list

Next you want to filter on that inner div , so we just add another predicate

//*[@class = 'item_inside'][*[@class = 'food_list']][*[@class = 'one_line']//*[@class = 'headline_title_content headline_title_2' and @aria-label = 'Big Basket']]

So now you have selected every the //*[@class = 'item_inside'] with these conditions


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x