先说下我的版本
谷歌浏览器:94.0.4606.81
chromedriver:94.0.4606.61
蟒蛇:3.7.8
selenium:4.0.0
错误一:使用TouchActions滑动屏幕报错: Cannot call non W3C standard command while in W3C mode
解决一:
关闭w3c验证,网上绝大部分是这么解决的
opt = webdriver.ChromeOptions()
opt.add_experimental_option('w3c', False)
self.driver = webdriver.Chrome(options=opt)
我的不行,原因不详,并且很难搜到,好像是说:“
ChromeDriver无法调用非W3C标准的命令,而在W3C模式同时启动/产生一个新的web浏览器即Chrome的浏览器会话。
这里的主要问题是,当ChromeDriver的客户端请求符合W3C的会话,但ChromeDriver的响应不符合W3C规范时,会导致语言API出错。”
这里来源于网络不是本人观点,这里还有个链接,可能要翻墙
不报w3c的错后给我报这个错:‘dict’ object has no attribute ‘send_keys’
解决二:
我本来的selenium版本是4.0.0,我把selenium的版本降下来就好使了,降到了3.141
以下就是我的代码
from selenium import webdriver
from selenium.webdriver import TouchActions
from selenium.webdriver.common.by import By
class TestW:
def setup(self):
opt = webdriver.ChromeOptions()
opt.add_experimental_option('w3c', False)
self.driver = webdriver.Chrome(options=opt)
self.driver.implicitly_wait(5)
def teardown(self):
pass
def test_touchaction(self):
self.driver.get("https://www.baidu.com/")
self.driver.find_element(By.ID,'kw').send_keys("测试")
el_search = self.driver.find_element(By.ID,"su")
action = TouchActions(self.driver)
action.tap(el_search)
action.perform()
action.scroll_from_element(self.driver.find_element(By.ID,'kw'),0,10000).perform()
修改selenium版本的传送门
OK,结束