admin管理员组文章数量:1287497
Its been a while I'm trying to figure out a way to automatically accept SSL certs. But unfortunately no luck. So, here is the case, I'm working on selenium tests. And, every time when I run the test on chrome, a small pop-up appears asking to select a certificate.
I tried this in python: How to deal with certificates using Selenium?
I also tried (in javascript):
var options = new chrome.Options();
options.addArguments("--ignore-certificate-errors")
But it doesn't seems to work!
In firefox, there is an option to automatically selects certs. Is there any way in selenium or in chrome settings which automatically selects the certs? Will ENTER/RETURN keys in selenium work?
EDITED: Below is my code. Is this the right way to use?
var launch = function(){
var options = new chrome.Options();
options.addArguments("--test-type");
/* Also tried options.addArguments(“--ignore-certificate-errors")
*/
var driver = new webdriver.Builder()
.usingServer('http://127.0.0.1:4444/wd/hub')
.setChromeOptions(options)
.build();
driver.get(url)
}
P.S Here, I'm using JavaScript.
Its been a while I'm trying to figure out a way to automatically accept SSL certs. But unfortunately no luck. So, here is the case, I'm working on selenium tests. And, every time when I run the test on chrome, a small pop-up appears asking to select a certificate.
I tried this in python: How to deal with certificates using Selenium?
I also tried (in javascript):
var options = new chrome.Options();
options.addArguments("--ignore-certificate-errors")
But it doesn't seems to work!
In firefox, there is an option to automatically selects certs. Is there any way in selenium or in chrome settings which automatically selects the certs? Will ENTER/RETURN keys in selenium work?
EDITED: Below is my code. Is this the right way to use?
var launch = function(){
var options = new chrome.Options();
options.addArguments("--test-type");
/* Also tried options.addArguments(“--ignore-certificate-errors")
*/
var driver = new webdriver.Builder()
.usingServer('http://127.0.0.1:4444/wd/hub')
.setChromeOptions(options)
.build();
driver.get(url)
}
P.S Here, I'm using JavaScript.
Share Improve this question edited May 23, 2017 at 12:23 CommunityBot 11 silver badge asked Nov 16, 2015 at 20:16 DanaDana 1391 gold badge1 silver badge10 bronze badges 7-
Use
--disable-web-security
– SLaks Commented Nov 16, 2015 at 20:17 - @SLaks Using your mand it still asks for certs. – Dana Commented Nov 16, 2015 at 20:34
-
Try starting chrome with option
--ignore-certificate-errors
. See peter.sh/experiments/chromium-mand-line-switches – Steffen Ullrich Commented Nov 16, 2015 at 21:37 - @SteffenUllrich Thanks! It works when I pass this mand in the terminal like this: chrome.exe --ignore-certificate-errors. But how do I pass in the same argument in the selenium code. I tried this: var options = new chrome.Options(); options.addArguments("--ignore-certificate-errors"); And this doesn't seems to work. Any suggestions? – Dana Commented Nov 16, 2015 at 22:45
- @SteffenUllrich chrome.exe --ignore-certificate-errors This doesn't seems to work any more! – Dana Commented Nov 16, 2015 at 23:07
4 Answers
Reset to default 3ACCEPT_SSL_CERTS
is one of the browser's desired capability that tells the browser to accept / deny ssl certificates by default.
below is a sample code for accepting SSL certificates in chrome:
DesiredCapabilities cap=DesiredCapabilities.chrome();
// Set ACCEPT_SSL_CERTS variable to true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
// Set the driver path
System.setProperty("webdriver.chrome.driver","Chrome driver path");
// Open browser with capability
WebDriver driver=new ChromeDriver(cap);
It is major problem with Chrome versions above v.80. I am currently using version 84.0.4147.105 which won't accept or ignore SSL certificate. The one thing to do is to downgrade Chrome version below v.80, especially for those of you who are building test cases in local Host applications.
Example using Selenium-grid and Chrome
const { Builder, until, By } = require("selenium-webdriver");
const capabilities = {
browserName: "chrome",
acceptInsecureCerts: true,
};
// alternative require `Capabilities` and do like this:
// const capabilities = Capabilities.chrome().setAcceptInsecureCerts(true);
try {
const driver = await new Builder()
.usingServer("http://localhost:4444/wd/hub")
.withCapabilities(capabilities)
.build();
await driver.get("https://frontend");
// tests
const el = await driver.wait(until.elementLocated(By.id("root")), 2000);
await driver.wait(until.elementIsVisible(el), 2000);
expect(el).not.toBeNull();
// tear down
await driver.quit();
} catch (err) {
throw new Error(err);
}
chrome_options = ChromeOptions()
chrome_options.add_argument('--lang='+language)
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--allow-running-insecure-content')
chrome_options.add_argument('--disable-web-security')
chrome_options.add_experimental_option('useAutomationExtension', False)
if headless :
chrome_options.set_headless()
if remote :
self.driver = webdriver.Remote(mand_executor=wd,desired_capabilities=chrome_options.to_capabilities(),options=chrome_options)
else:
self.driver = webdriver.Chrome(desired_capabilities=chrome_options.to_capabilities(),options=chrome_options)
本文标签: javascriptHow to automatically accept SSL certs in chromeStack Overflow
版权声明:本文标题:javascript - How to automatically accept SSL certs in chrome? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741314323a2371829.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论