如何在Selenium搭配Chrome浏览器时启用平滑滚动?
在Selenium中开启Chrome 132+的平滑滚动实验性选项
Chrome 132版本新增了平滑滚动的实验性选项,默认状态下未启用。要在Selenium中开启该功能,只需通过ChromeOptions添加对应的实验性配置即可,具体代码示例如下:
from selenium import webdriver options = webdriver.ChromeOptions() # 通过浏览器偏好设置开启平滑滚动 options.add_experimental_option('prefs', { 'profile.default_content_settings.smooth_scroll': 1 }) # 若上述配置不生效,可尝试直接启用对应实验特性 # options.add_experimental_option('enable_features', ['SmoothScroll']) driver = webdriver.Chrome(options=options)
说明:
- 第一种方式是通过设置Chrome的用户偏好来开启平滑滚动,这是更直接的配置方式
- 若偏好设置未生效,可以尝试第二种启用实验特性的方式,对应Chrome浏览器中
chrome://flags/#smooth-scrolling的手动开启操作
内容的提问来源于stack exchange,提问作者bdi
相关产品推荐
相关产品推荐

