enter image description here

I am trying to automate something on shopify, and depending on what the variable (lets say x) is, I want it to go into that list.

For example, if x=2, then from that ul/li(list), how can I make it click the 2nd option (Standard 3pcs)?

Any help would be appreciated!

  • Do you want to click the <li> element? Or the check-box within? If you only click on the <li> it may not necessarily click/select the check-box. So if possible share your HTML with the check-box element so that people can help you in the right way. Jun 17, 2022 at 7:07

1 Answer 1


I found the answer!

You can use "/li[1]" at the end for picking the first item on the list. If you want the second item, then it would be "/li[2]" and so forth.

My example:

search = driver.find_element_by_xpath("//ul[@class='Polaris-ResourceList_r589e']/li[" + str(variant[x]) + "]").click()

In this example, I am using a variable for the #, but if it's static for you, and you only need to get the 2nd item on the list, then it would be this:

search = driver.find_element_by_xpath("//ul[@class='Polaris-ResourceList_r589e']/li[2]").click()

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.