问题描述:
在 AirtestIDE 使用 airtest-selenium 做 airtest-selenium做Web自动化测试 时,
# 引入selenium的webdriver模块
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import WebChrome
#创建一个实例,代码运行到这里,会打开一个chrome浏览器
driver = WebChrome() # 这一步报错
driver.implicitly_wait(20)
发现插入初始化代码后,遇到该问题(ChromeDriver 不支持119以外的版本)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 119
Current browser version is 131.0.6778.86 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe
解决办法:
1.检查ChromeDriver和Chrome版本
打开Chrome >> 设置 >> 关于Chrome 查看版本信息
打开cmd:输入chromedriver --version发现并不能查询出 ChromeDriver版本信息
(不是很懂为什么查询不出来,电脑好像没安装)
2.更新ChromeDriver
无妨,不慌,先更新一波ChromeDriver版本,下载对应chrome版本的ChromeDriver,找到 对应的Version 和 匹配的Platform 下载下来解压
参考网站:Chrome for Testing availability
能用cmd查询出ChromeDriver位置的只需要下载对应版本的ChromeDriver替换掉ChromeDriver即可
3.指定ChromeDriver路径(推荐方法二)
方法一:
回到脚本中,替换原来的语句driver = WebChrome() ,更换executable_path路径
但是这个方法会导致部分其他自动化测试功能受影响
# -*- encoding=utf8 -*-
__author__ = "admin"
from airtest.core.api import *
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import WebChrome
# driver = WebChrome()
# 原来上面行替换掉,executable_path是你刚刚下载的chromedriver的位置
driver = webdriver.Chrome(executable_path='D:\chromedriver-win64/chromedriver')
driver.implicitly_wait(20)
auto_setup(__file__)
方法二:
回到脚本中,替换原来的语句driver = WebChrome() ,别忘了导包Options,然后选取浏览器chrome.exe的位置和刚刚下载的ChromeDriver的位置
# -*- encoding=utf8 -*-
__author__ = "admin"
from airtest.core.api import *
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import WebChrome
# 记得导入相应的包
from selenium.webdriver.chrome.options import Options
# 创建浏览器选项,选择chrome.exe位置
opt = Options()
opt.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
# 创建WebChrome实例,选择下载的 chromedriver 位置
driver = WebChrome(options=opt,executable_path=r"D:\chromedriver-win64/chromedriver")
driver.implicitly_wait(20)
auto_setup(__file__)
不知道chrome.exe在哪怎么办?打开cmd:输入where chrome.exe查询
更改完成后,就可以正常的打开Chrome进行自动化测试啦~