Chrome 浏览器:
Chrome64(已安装)、Chrome46(绿色版);
chromedrvier:
64 版-chromedriver(2.35),46 版-chromedriver(2.21);
selenium 版本-2.53.6,python 版本-2.7.13
根据最新 chrome 浏览器-chromedriver 映射表,确认客户端已下载对应版本的 chromedriver 文件。分别执行两段代码。其中 “#chrome64 版本代码” 正常启动 64 版 Chrome,而 “#chrome46 版本代码” 启动时会出现浏览器并闪退。
异常如下:
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/spider20180515/redo1.py", line 22, in <module>
open_chrome46 = webdriver.Chrome(chrome_driver46,chrome_options=chrome_options)
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"(60A2546D3AD2FCBDA5FF944DAA0A8F28)","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=64.0.3282.186)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
执行代码:
#chrome64版本
# chrome_driver64 = "C:\Users\Administrator\Downloads\chromedriver64\chromedriver.exe"
# os.environ["webdriver.chrome.driver"] = chrome_driver64
# chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument("--user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data\Default")
# open_chrome64 = webdriver.Chrome(chrome_driver64, chrome_options=chrome_options)
# open_chrome64.get("http://192.168.2.99:9080/jcbk/")
#chrome46版本
chrome_driver46 = "C:\Users\Administrator\Downloads\chromedriver46\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chrome_driver46
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--user-data-dir=C:\Users\Administrator\Downloads\GoogleChrome_46.0.2490.86_PortableSoft\GoogleChromePortable\App\Google Chrome\PortableProfile\Default")
open_chrome46 = webdriver.Chrome(chrome_driver46,chrome_options=chrome_options)
# open_chrome46.get("http://192.168.2.99:9080/jcbk/") executable_path="C:/Users/Administrator/Downloads/GoogleChrome_46.0.2490.86_PortableSoft/GoogleChromePortable/ChromePortable.exe",
open_chrome46.get("http://www.baidu.com")