Chrome options Proxy Bypass List not working - selenium

I've been trying to add arguments to my Chrome Options to use a proxy and to ignore certain URL's.
I've followed the documentation and am trying to run this very simple test:
#Test
public void myTest(){
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=http://XXX.XX.XX.XX:8080");
options.addArguments("--proxy-bypass-list=http://www.google.com");
System.setProperty("webdriver.chrome.driver", "C:/drivers/chromeDriver/win/chromedriver.exe");
ChromeDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
}
}
I've also tried with the variation:
options.addArguments("--proxy-bypass-list=*");
But it won't open the URL, is there something I'm doing wrong?

I guess you should use chromedriver.exe instead of eclipse.exe while setting property and make sure you have compatible chromedriver as per current version available in your system.
Here we go :
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=http://XXX.XX.XX.XX:8080");
options.addArguments("--proxy-bypass-list=https://www.google.com");
System.setProperty("webdriver.chrome.driver", "driver_location\\chromedriver.exe");
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com");

Related

Selenium newer Chrome cannot disable browser notification (Tried other solns)

I know this is an old question, and I've tried answers from a few posts such as Disable Chrome notifications (Selenium)
Unfortunately none worked, the browser notification popup still comes and interrupts my simulations.
My Chrome version is 75.0.3770.100 (Official Build) (64-bit), running on MacOS.
Edit:
After this question was marked as a duplicate of How to disable push-notifications using Selenium for Firefox and Chrome?, I've tried the solutions, but it still did not work for me.
String chromePath = "somepath/selenium-2.48.2/chromedriver";
System.setProperty("webdriver.chrome.driver", chromePath);
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");
driver = new ChromeDriver(options);
Below are the original solutions I tried.
String chromePath = "somepathto/chromedriver";
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver(chromeOptions);
// Login
try {
driver.get(sometestURL);
driver.manage().window().maximize();
// do some operations
} catch (Exception ex) {
System.out.println(ex);
}
I also tried this:
String chromePath = "somepath/selenium-2.48.2/chromedriver";
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver(chromeOptions);
But the notification still comes "xxxxwebsite wants to show notifications Allow Block" on the upper left of the window.
What I did not do right?
I just tested this on Windows with Chrome 75.0.3770.142 (64 bit) and ChromeDriver 75.0.3770.90 (see log below) against web site https://www.nzz.ch (because it asks for permission to show push notifications). I used Selenium 3.14.0.
08:27:37.184 [main] INFO i.g.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\xxxxx\.m2\repository\webdriver\chromedriver\win32\75.0.3770.90\chromedriver.exe
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770#{#1003}) on port 32864
For me the switch also mentioned here and in the linked resources reliably deactivates the popup from being displayed:
options.addArguments("--disable-notifications");
Changing the default setting profile.default_content_setting_values.notifications is not necessary in my case. So if this does not work for you
either you are not setting the option correctly,
you are using a (possibly outdated) ChromeDriver version not supporting it or
for some reason on MacOS the driver does not implement it.
P.S.: In both Firefox and Chrome for me it was not problem to e.g. click links and navigate to other pages even during the notification pop-up was shown. Did you have any problems there or is the pop-up just an annoyance?

selenium RemoteWebDriver opens but ChromeOptions are not passed to Selenium Grid

I have been trying to resolve a few issues with RemoteWebDriver and ChromeOptions using docker and selenium grid. The main issue is with the proxy but I half resolved that with a proxy pac file passing the pac file url as an arg into ChromeOptions. The below code runs great in docker debug and standalone locally but as soon as I try with the grid or deploy and run with bamboo the driver opens and I can see that ChromeOptions are not being passed because the poxy pac file is not being used and it's just frozen at org.openqa.selenium.remote.ProtocolHandshake createSession. I have been researching for a few weeks now and I am at a hard blocker with this now. I have seen some posts that DesiredCapabilities is deprecated but I have not found a way to implement ChromeOptions without it.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url= http://ProxyPacURL.com");
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
Update to latest Selenium Jars, make sure your java is version 1.8 or greater, then you can pass ChromeOptions into the driver because DesiredCapabilities is deprecated. I am now able to run selenium docker nodes with selenium grid and all ChromeOptions arguments are now being passed to the containers.
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
I was facing same issue and I have found the solution as below:
We need to set "goog:chromeOptions" instead of "chromeOptions".
In your Java code, following line is present:
dc.setCapability(ChromeOptions.CAPABILITY, options);
If you navigate to ChromeOptions.CAPABILITY, you will notice that it is a constant with value "chromeOptions". This works fine for local web driver, but not for remote web driver (i.e. selenium grid).
Just change above line to this:
dc.setCapability("goog:chromeOptions", options);
Now when you execute your Java code, it will work fine and all your options will show their effect too.
I came across other pages, such as this, which referred to above solution.
Try this:
const GRID_HOST = 'http://localhost:4444/wd/hub';
var options = new chrome.Options();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");
driver = new webdriver.Builder()
.usingServer(GRID_HOST)
.forBrowser("chrome")
.setChromeOptions(options)
.build()

Is there a way to set Chrome extension settings using selenium?

I am able to place extension using crx file. However, I need to change some setting in Chrome extension using selenium. Is there any chrome API or somehow I can automate this part. Appreciate!
When you instantiate the ChromeDriver, try using the below code:
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Unable to find element on new tab link

When I run a browser with extension a pop up arise that says "Disable developer mode" to do so my script clicks on Disable, it opens a new tab with url "chrome://extensions/"
Now to click on checkbox of developer mode it always give an error "Unable to locate element."
driver.findelement(By.id("toggle-dev-on"));
http://prntscr.com/f8fbde
Here is the solution for your Question:
As per best practices to work with Selenium 3.4.0 you must download the latest chromedriver v2.29 from here, update your Google Chrome to 58.x.
Updating your chromedriver to v2.29 will solve your issue of Disable developer mode
To work with Google Chrome you can take help of ChromeOptions Class as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://gmail.com");
Let me know if this solves your Question.
You need to modify the appropriate browser profile to have JS disabled. Like for FireFox/Chrome you can tell Selenium which profile to use.
Chrome :
Map prefs = new HashMap();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
FireFox :
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("dom.webnotifications.enabled", false);
WebDriver driver = new FirefoxDriver(ffprofile);
Hope this will work out for your case.

Selenium:Google Chrome Options and capabilities

I just wanted to know is it possible to set homepage of Chrome using capabilities and Chrome options in Selenium.
Yes it is possible to instantiate ChromeDriver with using both DesiredCapabilities and ChromeOption to set your desired Homepage as below :-
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Map<String, Object> preferences = new HashMap<String, Object>();
preferences.put( "browser.startup.homepage", "http://my.home.page" );
preferences.put( "browser.startup.page", START_WITH_HOME_PAGE );
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
capabilities.setCapability( ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
Just to be clear, the capabilities you are trying to set here are options that you use to customize and configure a ChromeDriver session.
Below are the keys which you can use to set for that session:
"browser.startup.homepage", "startup.homepage_welcome_url", "startup.homepage_welcome_url.additional" etc.
You can pass URL for these or if you don't want you can also set something like : "about:blank" as value