如何 select python selenium 中的所有复选框?
How to select all the checkbox in python selenium?
当我尝试 select 过滤器中的所有项目时,只有当我手动滚动它时它才会被 select 编辑,如果不滚动就可见的几个选项变得 selected,如何 select 美食中 swiggy 过滤器中的所有选项?
此代码遍历过滤器列表并在必要时使用 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()
当我尝试 select 过滤器中的所有项目时,只有当我手动滚动它时它才会被 select 编辑,如果不滚动就可见的几个选项变得 selected,如何 select 美食中 swiggy 过滤器中的所有选项?
此代码遍历过滤器列表并在必要时使用 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()