更新:使用seleniumbase工作,根据评论。
在chromedriver更新到115版本后,建议使用管理器来处理驱动程序/可执行文件的安装,如下所示:
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
但我用的是VPN,所以连接被屏蔽了。如何手动指定chromedriver和chrome测试可执行文件的路径?
如果有人能把我链接到这方面的文档,我会非常乐意阅读它,但我甚至没有找到它。
编辑:我试过这个(我试过设置绝对路径,但没有帮助):
service = Service(executable_path='chromedriver.exe')
options = webdriver.ChromeOptions()
options.binary_location = 'chrome.exe'
driver = webdriver.Chrome(service=service, options=options)
得到了这个
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "C:\Users\p3000151\AppData\Local\pypoetry\Cache\virtualenvs\splunk_on_call-xABy5ETk-py3.8\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 49, in __init__
super().__init__(
File "C:\Users\p3000151\AppData\Local\pypoetry\Cache\virtualenvs\splunk_on_call-xABy5ETk-py3.8\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 54, in __init__
super().__init__(
File "C:\Users\p3000151\AppData\Local\pypoetry\Cache\virtualenvs\splunk_on_call-xABy5ETk-py3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in __init__
self.start_session(capabilities)
File "C:\Users\p3000151\AppData\Local\pypoetry\Cache\virtualenvs\splunk_on_call-xABy5ETk-py3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 291, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "C:\Users\p3000151\AppData\Local\pypoetry\Cache\virtualenvs\splunk_on_call-xABy5ETk-py3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
self.error_handler.check_response(response)
File "C:\Users\p3000151\AppData\Local\pypoetry\Cache\virtualenvs\splunk_on_call-xABy5ETk-py3.8\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.
Stacktrace:
GetHandleVerifier [0x00007FF7D0DD6F92+54962]
(No symbol) [0x00007FF7D0D44FF2]
(No symbol) [0x00007FF7D0BFA6AB]
(No symbol) [0x00007FF7D0C2702A]
(No symbol) [0x00007FF7D0C24E5E]
(No symbol) [0x00007FF7D0C63A5B]
(No symbol) [0x00007FF7D0C634D0]
(No symbol) [0x00007FF7D0C5B6E3]
(No symbol) [0x00007FF7D0C303E1]
(No symbol) [0x00007FF7D0C31624]
GetHandleVerifier [0x00007FF7D1129782+3538594]
GetHandleVerifier [0x00007FF7D117F520+3890240]
GetHandleVerifier [0x00007FF7D11779DF+3858687]
GetHandleVerifier [0x00007FF7D0E735B6+695510]
(No symbol) [0x00007FF7D0D50048]
(No symbol) [0x00007FF7D0D4C144]
(No symbol) [0x00007FF7D0D4C272]
(No symbol) [0x00007FF7D0D3C633]
BaseThreadInitThunk [0x00007FFDC2167614+20]
RtlUserThreadStart [0x00007FFDC29426B1+33]
日志如下所示:
[1695134982.210][INFO]: Starting ChromeDriver 118.0.5993.3 (7a51b9ea23325fae1ec1dad5a02c67c2240d7b11-refs/branch-heads/5993@{#7}) on port 60693
[1695134982.210][INFO]: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
[1695134982.677][INFO]: [86d49340f523de943fea4c30087657ec] COMMAND InitSession {
"capabilities": {
"alwaysMatch": {
"browserName": "chrome",
"goog:chromeOptions": {
"args": [ ],
"binary": "C:\\Users\\p3000151\\PycharmProjects\\SPLUNK ON CALL\\chrome.exe",
"extensions": [ ]
},
"pageLoadStrategy": "normal"
},
"firstMatch": [ {
} ]
}
}
[1695134982.679][INFO]: Populating Preferences file: {
"alternate_error_pages": {
"enabled": false
},
"autofill": {
"enabled": false
},
"browser": {
"check_default_browser": false
},
"distribution": {
"import_bookmarks": false,
"import_history": false,
"import_search_engine": false,
"make_chrome_default_for_user": false,
"skip_first_run_ui": true
},
"dns_prefetching": {
"enabled": false
},
"profile": {
"content_settings": {
"pattern_pairs": {
"https://*,*": {
"media-stream": {
"audio": "Default",
"video": "Default"
}
}
}
},
"default_content_setting_values": {
"geolocation": 1
},
"default_content_settings": {
"geolocation": 1,
"mouselock": 1,
"notifications": 1,
"popups": 1,
"ppapi-broker": 1
},
"password_manager_enabled": false
},
"safebrowsing": {
"enabled": false
},
"search": {
"suggest_enabled": false
},
"translate": {
"enabled": false
}
}
[1695134982.680][INFO]: Populating Local State file: {
"background_mode": {
"enabled": false
},
"ssl": {
"rev_checking": {
"enabled": false
}
}
}
[1695134982.686][INFO]: Launching chrome: "C:\Users\p3000151\PycharmProjects\SPLUNK ON CALL\chrome.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\Users\p3000151\AppData\Local\Temp\scoped_dir4444_743592924" data:,
[1695134982.714][INFO]: [86d49340f523de943fea4c30087657ec] RESPONSE InitSession ERROR unknown error: Failed to create Chrome process.
我用的是win 64可执行文件。这和我的VPN有关系吗?
1条答案
按热度按时间0dxa2lsx1#
以下是指定驱动程序路径和浏览器二进制文件位置的方法:
(The
.exe
适用于Windows。如果在Mac / Linux上,它不会在那里。您还可以使用SeleniumBase驱动程序管理器来解决此问题,这可能会避免通过VPN下载驱动程序时出现的速度缓慢。
(
pip install seleniumbase
,并使用python
运行):