I am trying to find the xpath / count for all the checkboxes under "Categories". but when I am trying to get xpath/count it is getting me all the checkboxes under "Categories" and under "Brands"

How can I get all checkboxes count under "Categories".

attaching the screenshot for the issue, Appreciate your help.

  • 2
    Hi please show the DOM for both category and brand,
    – PDHide
    Dec 18 '19 at 4:11

Please add the element structure for the brand also. Assuming, all elements under Brand and categories are under different levels, the xpath you could use is:


It seems both are in the same level:

i tested below locator:

//li[preceding-sibling::*//div[text()='SHOP BY CATEGORY']/..][following-sibling::*//a[@data-menu-id="10"]/..]

and also:


For amazon uk:

https://www.amazon.co.uk/: click the handburger menu and try out your self

enter image description here

so in your case you could use:

  • Thank you, but its counting all the checkboxes under "category" and "brands", I have attached updated screenshot of how the elements are defined under the category.
    – Ravi
    Dec 18 '19 at 14:08
  • @Ravi see the updated answer
    – PDHide
    Dec 18 '19 at 15:33
  • Thank you so much, your solution worked. :)
    – Ravi
    Dec 19 '19 at 1:50
  • @Ravi please also accept the answer by clicking the tick sign
    – PDHide
    Dec 19 '19 at 8:49
  • 1
    Done, Thank you so much.
    – Ravi
    Dec 21 '19 at 15:01

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.