踩大坑了家人们!!!!
Linux+Microsoft Edge+selenium在本地实现无头模式下的自动化测试是没问题的,但是放到linux服务器上跑是不行的,因为Microsoft Edge的驱动msedgedriver在版本79.0.309.0之后就出现了一些问题,即使你的浏览器和驱动版本一致也会一直报错:
Message: session not created: No matching capabilities found
解决方法,把selenium升级到4.0.0.a5版本,此时selenium可以支持webdriver.edge.options
更改代码为以下形式
from selenium import webdriver
from selenium.webdriver.edge.options import Options
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.webdriver import WebDriver
…
…
driveroptions = Options()
driveroptions.use_chromium = True
driveroptions.add_argument(‘–start-maximized’)
driveroptions.binary_location = env_programfiles_x86 + “\Microsoft\Edge\Application\msedge.exe”
service = Service(executable_path=”msedgedriver.exe”)
driver = webdriver.Edge(options=driveroptions, service=service)
driver.set_page_load_timeout(40)
driver.get(page_url)