selenium4 使用 TouchActions 的 scroll 方法报错,可有破解之法

2022-05-17 18:37:51 +08:00
 396930154

selenium 4.1.0 ChromeDriver 97.0.4692.71 Google Chrome 97.0.4692.71

示例代码:

print('start')

from selenium import webdriver

from selenium.webdriver.common.touch_actions import TouchActions

from selenium.webdriver.chrome.service import Service as ChromeService

options = webdriver.ChromeOptions()

options.add_experimental_option("excludeSwitches", ["enable-automation"])

options.add_experimental_option("useAutomationExtension", False)

options.add_experimental_option('w3c', False)

service = ChromeService(executable_path=CHROMEDRIVER_PATH)

driver = webdriver.Chrome(service=service, options=options)

driver.get('https://www.v2ex.com/')

actions = TouchActions(driver)

actions.scroll(100,500).perform()

print('end')

去掉 options.add_experimental_option('w3c', False)这句代码会报如下错误:selenium.common.exceptions.WebDriverException: Message: unknown command: Cannot call non W3C standard command while in W3C mode

selenium 版本不降,w3c 且必须设置为 True 的时候还有办法使用 TouchActions 的 scroll 方法吗?

471 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/853522

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX