Use*_*716 8 python selenium google-chrome selenium-grid selenium-chromedriver
我正在尝试使用带有ChromeDriver的硒在本地主机(没有HTTPS)上运行集成测试。
Chrome需要使用https证书,但是根据这个问题,我知道我可以使用arg来绕过它--ignore-certificate-errors
我也增加了自己的功能acceptInsecureCerts,因为这似乎是适当的做法(docs)
chromedriver的响应仍然不是我所期望的:
该网站无法提供安全连接,应用发送的响应无效。ERR_SSL_PROTOCOL_ERROR
我的代码如下:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# make options (principally to ignore certificate)
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
# add acceptInsecureCerts
capabilities = options.to_capabilities()
capabilities['acceptInsecureCerts'] = True
print(capabilities) # see below
driver = webdriver.Remote(
command_executor=SELENIUM_HUB,
desired_capabilities=capabilities
)
print(driver.__dict__) # see further below
app_login_url = 'http://app:8000/accounts/login/'
driver.get(app_login_url)
Run Code Online (Sandbox Code Playgroud)
我的能力:
{'acceptInsecureCerts': True,
'browserName': 'chrome',
'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],
'extensions': []},
'platform': 'ANY',
'version': ''}
Run Code Online (Sandbox Code Playgroud)
这是我的驱动程序信息,似乎只acceptInsecureCerts考虑了arg:
{'_file_detector': <selenium.webdriver.remote.file_detector.LocalFileDetector object at 0x7fb42bde10f0>,
'_is_remote': True,
'_mobile': <selenium.webdriver.remote.mobile.Mobile object at 0x7fb42bb5e400>,
'_switch_to': <selenium.webdriver.remote.switch_to.SwitchTo object at 0x7fb42bdd4898>,
'capabilities': {'acceptInsecureCerts': True,
'acceptSslCerts': True,
'applicationCacheEnabled': False,
'browserConnectionEnabled': False,
'browserName': 'chrome',
'chrome': {'chromedriverVersion': '74.0.3729.6 '
'(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})',
'userDataDir': '/tmp/.com.google.Chrome.vc1ZvB'},
'cssSelectorsEnabled': True,
'databaseEnabled': False,
'goog:chromeOptions': {'debuggerAddress': 'localhost:40815'},
'handlesAlerts': True,
'hasTouchScreen': False,
'javascriptEnabled': True,
'locationContextEnabled': True,
'mobileEmulationEnabled': False,
'nativeEvents': True,
'networkConnectionEnabled': False,
'pageLoadStrategy': 'normal',
'platform': 'Linux',
'proxy': {},
'rotatable': False,
'setWindowRect': True,
'strictFileInteractability': False,
'takesHeapSnapshot': True,
'takesScreenshot': True,
'timeouts': {'implicit': 0,
'pageLoad': 300000,
'script': 30000},
'unexpectedAlertBehaviour': 'ignore',
'version': '74.0.3729.169',
'webStorageEnabled': True,
'webdriver.remote.sessionid': '1cf77f237e966bac6ca15d4d9c107423'},
'command_executor': <selenium.webdriver.remote.remote_connection.RemoteConnection object at 0x7fb42be0cf98>,
'error_handler': <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7fb427d08a20>,
'session_id': '1cf77f237e966bac6ca15d4d9c107423',
'w3c': False}
Run Code Online (Sandbox Code Playgroud)
为什么我仍然看到ERR_SSL_PROTOCOL_ERROR?
此错误消息...
This site can’t provide a secure connection app sent an invalid response. ERR_SSL_PROTOCOL_ERROR
Run Code Online (Sandbox Code Playgroud)
...暗示ChromeDriver无法启动/产生新的WebBrowser,即本地主机上的Chrome浏览器会话。
正如你所看到的这个问题,你对本地主机(没有HTTPS)按照此评论一眼罩的解决办法是增加argument --allow-insecure-localhost通过chromeOptions()如下:
'goog:chromeOptions': {'args': ['--allow-insecure-localhost'],
'extensions': []}
Run Code Online (Sandbox Code Playgroud)
但是你的主要问题似乎是与能力,你必须设置platform为集合S ANY如下:
{'acceptInsecureCerts': True,
'browserName': 'chrome',
'goog:chromeOptions': {'args': ['--ignore-certificate-errors'],
'extensions': []},
'platform': 'ANY',
'version': ''}
Run Code Online (Sandbox Code Playgroud)
正如WebDriver-W3C Living Document的platformName部分提到的那样,以下平台名称通常具有易于理解的语义,并且在匹配功能时,可以通过将其作为已知操作系统的有效同义词来实现最大的互操作性:
Key System
--- ------
"linux" Any server or desktop system based upon the Linux kernel.
"mac" Any version of Apple’s macOS.
"windows" Any version of Microsoft Windows, including desktop and mobile versions.
Run Code Online (Sandbox Code Playgroud)
注意:此列表并不详尽。
从New Session返回功能时,返回更特定的platformName是有效的,从而允许用户正确标识WebDriver实现在其上运行的操作系统。
因此"platform":"ANY",与其传递期望的功能对象,不如说是更具体的"platform":"linux"方法。
您可以在带有参数的http POST到/ session的Curl错误中找到相关的讨论:{“ desiredCapabilities”:{“ browserName”:“ chrome”,“ platform”:“ ANY” with Selenium和PHPUnit
有关ChromeDriver,Chrome和Selenium Client vrsion的更多信息将有助于我们以更好的方式分析问题。但是,根据ChromeDriver的历史记录,最近几个版本的ChromeDriver中解决了与证书错误处理相关的以下问题:
--ignore-certificate-errors忽略,只能通过devtools进行设置。因此,有必要certificateError在以浏览器为目标的DevTools客户端上覆盖和处理事件。一个补丁发布实施新DevTools方法的使用,以替代证书错误处理浏览器的宽这使得在无头模式忽略证书错误太多。Security.enable/ Security.setOverrideCertificateErrors命令在尝试导航之前。一个修复用简单的“忽略所有证书错误”模式发布,取而代之的是新的,而不是过时的旧覆盖命令setIgnoreCertificateErrors命令,它也暴露了在浏览器上的目标的安全域,以促进全球范围内应用该重写了整个浏览器。--allow-insecure-localhostacceptInsecureCerts--ignore-certificate-errors'chromedriverVersion': '74.0.3729.6',请确保您也正在使用'chrome': '74.0'(根据ChromeDriver v74.0.3729.6发行说明)| 归档时间: |
|
| 查看次数: |
1156 次 |
| 最近记录: |