简体   繁体   English

设置Selenium WebDriver的特定功能

[英]Setting specific capabilities for selenium webdriver

I'm trying to set some specific capabilities for a Selenium Webdriver. 我正在尝试为Selenium Webdriver设置一些特定功能

In this example i want to change a capability of the webdriver for the Firefox browser. 在此示例中,我想更改Firefox浏览器capability of the webdriver I'm trying to this in Javascript . 我正在使用Javascript尝试此操作。

this.driver = new selenium.Builder().forBrowser('firefox').build();

I tried things like calling .withCapabilities() but it is not working as i expected it and crashes the program. 我尝试了诸如调用.withCapabilities()类的事情,但是它没有按我预期的那样工作并使程序崩溃。

In specific i want to set the ' acceptSslCerts ' capability to true because it is false in default. 具体来说,我想将“ acceptSslCerts ”功能设置为true,因为默认情况下它为false。

Does anybody have an idea on how to this? 有人对此有想法吗? I'm not able to find anything in the API reference or on the internet. 我无法在API参考或互联网上找到任何内容。

For firefox, through FirefoxProfile , you can accept SSL certificate. 对于Firefox,可以通过FirefoxProfile接受SSL证书。

eg FirefoxProfile firefoxProfile = new FirefoxProfile(); 例如FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setAcceptUntrustedCertificates(true) firefoxProfile.setAcceptUntrustedCertificates(真)

For googlechrome, through DesiredCapability , you can set the browser property. 对于googlechrome,可以通过DesiredCapability设置浏览器属性。

This works fine for me, to set CORS in my chrome browser. 在我的chrome浏览器中设置CORS对我来说效果很好。

const { Builder, By, Key, until } = require('selenium-webdriver');

const capabilities = {
    'chromeOptions': {
        'args': ['--disable-web-security', '--user-date-dir']
    }
}
let driver = new Builder().withCapabilities(capabilities).forBrowser('chrome').build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM