首页 > 解决方案 > SELENIUM - 浏览器在使用代理和所需功能时以不安全模式启动

问题描述

    // 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 之后它也无法正常工作

标签: selenium-webdriverbrowsermob-proxy

解决方案


推荐阅读