Home > Software engineering >  How to select all the checkbox in python selenium?
How to select all the checkbox in python selenium?

Time:05-18

When I try to select all the items in filter, it is selected only when I scroll it manually if not only few options which is visible without scrolling is getting selected, How to select all the options in swiggy filter in cuisine?enter image description here

CodePudding user response:

This code loops over the list of filters and scrolls down when necessary using javascript.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service(chromedriver_path))

...do something and then open the Filters sidebar...

# loop over the filters and scroll if necessary
for box in driver.find_elements(By.CSS_SELECTOR, 'input[type=checkbox]   span'):
    driver.execute_script('arguments[0].scrollIntoView({block: "center"});', box)
    box.click()
  • Related