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
    Commented Dec 18, 2019 at 4:11

1 Answer 1


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
    Commented Dec 18, 2019 at 14:08
  • @Ravi see the updated answer
    – PDHide
    Commented Dec 18, 2019 at 15:33
  • Thank you so much, your solution worked. :)
    – Ravi
    Commented Dec 19, 2019 at 1:50
  • @Ravi please also accept the answer by clicking the tick sign
    – PDHide
    Commented Dec 19, 2019 at 8:49
  • 1
    Done, Thank you so much.
    – Ravi
    Commented Dec 21, 2019 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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