extended-salmon
extended-salmon•3y ago

Checking boxes with Selenium

Does anyone know what I'm doing wrong? I've tried finding the element and clicking it but get an error that the element isn't interactable. I have also tried executing a script that would check the boxes and the actor will succeed in running but after looking at the screenshot no checkboxes were checked. Any help in the right direction is appreciated. Here's the code that gets the error of element not interactable:
checkboxes = driver.find_elements(By.XPATH, "//input[@type='checkbox']")
for checkbox in checkboxes:
if not checkbox.is_selected():
checkbox.click()
checkboxes = driver.find_elements(By.XPATH, "//input[@type='checkbox']")
for checkbox in checkboxes:
if not checkbox.is_selected():
checkbox.click()
Here's the code that runs but does nothing:
checkboxes = driver.find_elements(By.XPATH, "//input[@type='checkbox']")
for checkbox in checkboxes:
if not checkbox.is_selected():
driver.execute_script("arguments[0].click();", checkbox)
checkboxes = driver.find_elements(By.XPATH, "//input[@type='checkbox']")
for checkbox in checkboxes:
if not checkbox.is_selected():
driver.execute_script("arguments[0].click();", checkbox)
2 Replies
Pepa J
Pepa J•3y ago
hello @SmilinDesperado , It is hard to say when we don't know the website. - I would suggest count the elements, to know you are using the right selector (not all checkbox has to be implemented only by semantic <input type="checkbox"> element). - Improve a logging to see if the checkboxes are already really unselected. - Another thing could be that this input[type="checkbox"] elements are not visible (and that also means clickable/interactable), when you execute the code - often they are just used as a state-holders for submitting the form, but the real interaction is done with different <div> based elements, because it allows to do a lot more fancy css styling.
extended-salmon
extended-salmonOP•3y ago
never mind. i was able to figure it out. my code that executes the script does work, it was my screenshots that i had setup wrong and was basically just showing myself the same one multiple times 😅 thank you for your help

Did you find this page helpful?