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

推荐答案

这段代码在过滤器列表上循环,并在必要时使用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()

Python相关问答推荐

运行终端命令时出现问题:pip start anonymous"

如果值不存在,列表理解返回列表

"使用odbc_connect(raw)连接字符串登录失败;可用于pyodbc"

如何在WSL2中更新Python到最新版本(3.12.2)?

把一个pandas文件夹从juyter笔记本放到堆栈溢出问题中的最快方法?

python panda ExcelWriter切换动态公式到数组公式

如何删除重复的文字翻拍?

使用SQLAlchemy从多线程Python应用程序在postgr中插入多行的最佳方法是什么?'

Python如何导入类的实例

如何写一个polars birame到DuckDB

用0填充没有覆盖范围的垃圾箱

文本溢出了Kivy的视区

高效地计算数字数组中三行上三个点之间的Angular

为什么在生成时间序列时,元组索引会超出范围?

Groupby并在组内比较单独行上的两个时间戳

将参数从另一个python脚本中传递给main(argv

如何让doctest在mkdocs的标记代码块中运行示例?

打印:添加具有不同填充 colored颜色 的矩形

在Matplotlib中通过特定的Y值而不是 colored颜色 来改变alpha/opacity

Django/Python-UpdateView中的Delete函数正在复制,而不是删除