Selenium和BrowserMobProxy不显示和设置Java中的浏览器引用,如何设置

时间:2018-11-23 05:34:31

标签: java selenium browsermob-proxy

public class Test {

public static void main(String[] args) throws Exception{

        String driverGoogleChromePath = "D:\\Project Doc\\Jar\\selenium\\chromedriver_win32\\chromedriver.exe";
        String refererurl = "http://www.iteye.com/";
        String hostAndPort = "112.91.159.66:3128";
        int port = 3128;
        //String host = "112.91.159.66";

        System.setProperty("webdriver.chrome.driver",driverGoogleChromePath);
        //start the proxy
        BrowserMobProxy proxy = new BrowserMobProxyServer();
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Referer",refererurl);
        proxy.addHeaders(headers);
        proxy.start(port);


        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
        seleniumProxy.setHttpProxy(hostAndPort)
                     .setSslProxy(hostAndPort)
                     .setFtpProxy(hostAndPort);

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
        ChromeOptions option = new ChromeOptions().merge(capabilities);

        WebDriver driver = new ChromeDriver(option);
        Thread.sleep(3000);
        driver.get("http://www.java1234.com/");
        proxy.stop();
        //driver.close();
    }

这是我的Java代码,我将引荐来源网址设置为使用.addHeaders,但是当我运行它时,浏览器未显示引荐来源网址,为什么,该怎么显示呢?

硒:selenium-server-standalone-3.141.5.jar 浏览器:browsermob-dist-2.1.4.jar

enter image description here

0 个答案:

没有答案