硒-使用代理和所需功能时,浏览器以非安全模式启动

时间:2019-01-18 04:53:07

标签: selenium-webdriver browsermob-proxy

    // start the proxy
    BrowserMobProxy proxy = new BrowserMobProxyServer();
    proxy.start(0);

    // get the Selenium proxy object
    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

    // configure it as a desired capability
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    // start the browser up
    @SuppressWarnings("deprecation")
    WebDriver driver = new ChromeDriver(capabilities);

    // enable more detailed HAR capture, if desired (see CaptureType for the
    // complete list)

    proxy.enableHarCaptureTypes(CaptureType.REQUEST_BINARY_CONTENT, CaptureType.REQUEST_HEADERS,
            CaptureType.REQUEST_CONTENT, CaptureType.REQUEST_COOKIES, CaptureType.RESPONSE_BINARY_CONTENT,
            CaptureType.RESPONSE_CONTENT, CaptureType.RESPONSE_HEADERS, CaptureType.RESPONSE_COOKIES);

    // create a new HAR with the label
    proxy.newHar("google");

    // open website
    driver.get("https://www.google.co.in");

即使将ACCEPT_SSL_CERTS设置为True,它也无法正常工作,您能否建议如何以安全模式启动浏览器

0 个答案:

没有答案