Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver 3.0.1 chromedriver.exe 2.25 --whitelisted-ips=""

I would like to have a solution that is able to open a chrome browser and able to open a url through a proxy.

I decided to use the followings:

  • Selenium WebDriver 3.0.1 with Java 1.8.0_111-b14

  • chromedriver.exe 2.25

I'm facing with a weird issue:

"Only local connections are allowed."

Please see the cause of my confusion

Please see my code:

package seleniumFiles;

import java.util.Arrays;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SeleniumClass {


    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\work\\selenium-java-3.0.1\\chromedriver.exe");

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability("network.proxy.http", "93.180.7.246");
        capabilities.setCapability("network.proxy.http_port", "8080");
        capabilities.setCapability("webdriver.chrome.args", Arrays.asList("--verbose --whitelisted-ips=''"));
        WebDriver driver = new ChromeDriver(capabilities);
        driver.get("http://www.whoishostingthis.com/tools/user-agent/");

    }

}

Running the "chromedriver.exe --verbose --whitelisted-ips=''" in cmd sais "Remote connections are allowed by a whitelist <''>" It seems like works but I cannot figure out what I did wrong in the code.

Any idea or suggestion appreciated.

like image 337
Gyorgy Avatar asked Oct 19 '25 09:10

Gyorgy


2 Answers

All answers with addArguments("--whitelisted-ips=''"); are wrong. This argument needs to be injected into chromedriver exe, not chrome.

If you use ChromeDriver loccaly directly from code, just insert lines below before ChromeDriver init

    System.setProperty("webdriver.chrome.whitelistedIps", "");

If you use it remotely (eg. Selenium hub/grid) you need to setup system property when node is run like in command:

java -Dwebdriver.chrome.whitelistedIps= testClass

or docker by passing JAVA_OPTS env

  chrome:
    image: selenium/node-chrome:3.141.59
    container_name: chrome
    depends_on:
      - selenium-hub
    environment:
      - HUB_HOST=selenium-hub
      - HUB_PORT=4444
      - JAVA_OPTS=-Dwebdriver.chrome.whitelistedIps=
like image 160
GetoX Avatar answered Oct 21 '25 21:10

GetoX


I may be late, I'm posting this so it can help someone. You can use chromeoptions to define all your arguments.

    System.setProperty("webdriver.chrome.driver", "/usr/local/chromedriver");

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--verbose");
    chromeOptions.addArguments("--whitelisted-ips=''");
    chromeOptions.addArguments("--proxy-server=93.180.7.246:8080");

    WebDriver driver = new ChromeDriver(chromeOptions);
    driver.get("http://www.whoishostingthis.com/tools/user-agent/");
like image 29
Sridhar Avatar answered Oct 21 '25 23:10

Sridhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!