Home > Net >  Selenium click all checkboxes in class?
Selenium click all checkboxes in class?

Time:05-03

I am using selenium to open a tableau visualization on a webpage. It has multiple checkboxes that represent filters for the viz. How do I click all of them? This is the relevant HTML:

HTML HERE

This is what I have tried so far with xpath

xpaths = { 'usernameTxtBox' : "//input[@name='username']",
           'passwordTxtBox' : "//input[@name='password']",
           'submitButton' :   "//button[@class='fycmrtt login-page_submit-button_f1pvbd5k low-density'][.='Sign In']",
           'Check' :        "//label[contains(@class,'tab-zone tab-widget tabSuppressVizTooltipsAndOverlays tabZone-filter fade-bg')]//child::input[@type='checkbox']"

         }

mydriver.find_element_by_xpath(xpaths['Check']).click()

CodePudding user response:

What you need to do is find_elements_by_xpath and put this into a list Then you need to create a loop to click each element in your list

CodePudding user response:

elems=driver.find_elements(BY.XPATH,"//div[starts-with(@id,'tab-ui-id')]//div[@role='checkbox']")
for elem in elems:
    elem.click()

You can grab all the checkboxes and then loop and click them.

  • Related