smitty_werben_jagerm
smitty_werben_jagerm

Reputation: 394

Selenium click all checkboxes in class?

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()

EDIT:

I've found that this line here plays some sort of role. Does this actually mean anything? The below is from a checked checkbox.

checked="checked" See Edit 1

Upvotes: 0

Views: 163

Answers (2)

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

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.

Upvotes: 1

Anand
Anand

Reputation: 1939

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

Upvotes: 1

Related Questions