自动化测试:Webdriver出错问题


#1

1、我的浏览器是360V10,10.0.1764.0,内核版本是63.0.3239.132
2、我下载的chromedriver.exe,版本号 74.0.3729.6,下载到了pthon37目录下了
3、系统环境window 64位
运行出现如下错误:


(FlaskProjects-BArbVR56) D:\FlaskProjects\FlaskHTTP\mytodoism>flask shell
Python 3.7.1rc2 (v3.7.1rc2:6c06ef7dc3, Oct 13 2018, 15:44:37) [MSC v.1914 64 bit (AMD64)] on win32
App: mytodoism [development]
Instance: D:\FlaskProjects\FlaskHTTP\mytodoism\instance
>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> driver = webdriver.Chrome()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.10240 x86_64)

请各位指教!


#2

你装chrome浏览器了吗?(需要安装chrome)


#3

我装的是360浏览器,它用的内核也是Chrome的


#4

似乎你需要这样设置一下?

__browser_url="C:\\Users\\...\\360se.exe"
chrome_options=Options()
chrome_options.binary_location=__browser_url

#5

你说的对,但现在出现了不同的错误提示,应该是浏览器版本与Chrome的版本不同原因,但浏览器360的版本号是63.0.3239.132吗?可没有对应的下载程序啊?


(FlaskProjects-BArbVR56) D:\FlaskProjects\FlaskHTTP\mytodoism>flask shell
Python 3.7.1rc2 (v3.7.1rc2:6c06ef7dc3, Oct 13 2018, 15:44:37) [MSC v.1914 64 bit (AMD64)] on win32
App: mytodoism [development]
Instance: D:\FlaskProjects\FlaskHTTP\mytodoism\instance
>>> from selenium.webdriver.chrome.options import Options
>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> _browser_url=r'C:\Users\张启宏\AppData\Roaming\360se6\Application\360se.exe'
>>> chrome_options = Options()
>>> chrome_options.binary_location=_browser_url
>>> driver=webdriver.Chrome(chrome_options=chrome_options)

DevTools listening on ws://127.0.0.1:52056/devtools/browser/2ad16248-697c-4857-beef-7bbc7234d349
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "c:\users\张启宏\.virtualenvs\flaskprojects-barbvr56\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 74
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.10240 x86_64)

>>>

QQ%E5%9B%BE%E7%89%8720190408215312


#6

This version of ChromeDriver only supports Chrome version 74

按照错误提示,你应该安装 Chrome 74。


#7


我下载的Chromedriver是74的啊,放在Python37的根目录下了,是不是因为该放在其他地方?还是浏览器版本不配套?


#8

需要搭配对应版本的 Chrome 浏览器使用,而不是 360 浏览器。


#9

是的,改成Chrome浏览器就可以了。但照理说360浏览器也是可以的,就是不知道360浏览器对应的驱动程序是哪个版本。