3

Is it possible to use proxy after starting chromedriver on the same browser?

EX:

  1. I start chrome driver
  2. Load website
  3. Put in info
  4. Use proxy
  5. Click submit

I think i found some ways to do it in python and JS but im not sure how to convert it to java

    2 Answers 2

    3

    As per Selenium's current implementation once you configure the WebDriver instance with the required Options and Capabilities and initialize the WebDriver session to open a Web Browser, you cannot change the capabilities runtime. Even if you are able to retrieve the runtime capabilities still you won't be able to change them back.

    So, in-order to use a proxy you have to initiate a new WebDriver session.

    here is @JimEvans clear and concise comment (as of Oct 24 '13 at 13:02) related to proxy settings capability:

    When you set a proxy for any given driver, it is set only at the time WebDriver session is created; it cannot be changed at runtime. Even if you get the capabilities of the created session, you won't be able to change it. So the answer is, no, you must start a new session if you want to use different proxy settings.

    You can find a relevant discussion in Set capability on already running selenium webdriver

      -1

      You can use ChromeOptions class.

      You can create an instance of ChromeOptions, which has convenient methods for setting ChromeDriver-specific capabilities. You can then pass the ChromeOptions object into the ChromeDriver constructor: ChromeOptions options = new ChromeOptions(); options.addExtensions(new File("/path/to/extension.crx")); ChromeDriver driver = new ChromeDriver(options); ChromeOptions options = new ChromeOptions(); // Add the WebDriver proxy capability. Proxy proxy = new Proxy(); proxy.setHttpProxy("myhttpproxy:3337"); options.setCapability("proxy", proxy); // Add a ChromeDriver-specific capability. options.addExtensions(new File("/path/to/extension.crx")); ChromeDriver driver = new ChromeDriver(options); 
      1
      • thanks for the quick reply but doesnt that open a new browser? i want to continue on the same driver and page because when i click submit website checks ip and if its been used they ban it and i only need to use proxy when clicking on submit but if i start the driver with proxy it runs through 10Mb of data per task so if im able to use proxy right before clicking submit then it saves a lot of data.
        – Cowsgo
        CommentedOct 1, 2019 at 5:48

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.