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

后端 未结 3 1066
旧巷少年郎
旧巷少年郎 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:29

    you can set proxy details with credentials here in your automation code as above answers explained but another way to do it without sharing your details in your java or python code with firefox profile.
    firefox provides profiles, we can create profile for every user and customize it for proxy ,bookmarks etc.
    windows user : open run(win+R) and type 'firefox -p'
    linux user : run command 'firefox -p'
    1- it will open a dialog box where you can create your profile then select that profile and open firefox.
    2- open a new tab and search 'about:config' .accept the Risk and Continue then click on show all
    3-here you can search and set all the property
    example:
    network.proxy.type   1
    1 for Manually
    2 for Automatic proxy
    for Manuall proxy -
    property                     value
    network.proxy.http              your proxy ip
    network.proxy.http_port               port number
    network.proxy.ssl               your proxy ip
    network.proxy.ssl_port               port number
    network.proxy.ftp               your proxy ip
    network.proxy.ftp_port               port number

    (to find your profile name )
    Linux : cd .mozilla/firefox/
    windows: Press. +R on the keyboard. A Run dialog will open. Type in: %APPDATA%\Mozilla\Firefox\Profiles\ Click OK. A window will open containing profile folders now load this profile in java code

    FirefoxOptions options = new FirefoxOptions();
    options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
    FirefoxProfile profile=new FirefoxProfile(new File("path of your profile"));
    options.setProfile(profile);
    WebDriver driver = new FirefoxDriver(options);
    System.setProperty("webdriver.gecko.driver", "path of gecko driver");
    driver.get("url");
    

提交回复
热议问题