How do I set a proxy for firefox using Selenium webdriver with Java?

后端 未结 3 1083
旧巷少年郎
旧巷少年郎 2020-12-20 02:35
System.setProperty(\"webdriver.gecko.driver\", \"E:\\\\geckodriver-v0.18.0-win64\\\\geckodriver.exe\");
    Proxy p = new Proxy();
    p.setSocksProxy(\"83.209.94.87         


        
3条回答
  •  孤城傲影
    2020-12-20 03:12

    Because a bug you cannot use the Proxy object as of now. You should use the below code

        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.socks", "83.209.94.87");
        profile.setPreference("network.proxy.socks_port", 35923);
    
        FirefoxDriver driver = new FirefoxDriver(profile);
        driver.get("https://www.ipinfo.io");
    

    The bug is discussed on https://github.com/mozilla/geckodriver/issues/764 and you see what the Marionette driver do in background on below link

    https://dxr.mozilla.org/mozilla-central/source/testing/marionette/session.js#155

    So above code just replicates the same

提交回复
热议问题