An old chromedriver.exe (2.36) works fine with all newer chrome browser versions without needing to update it. How is this possible? - selenium

I am using a selenium java testng project. Dependencies including chromedriver.exe are part of source code as of now and in the process of moving to ant + ivy.
Current selenium server standalone version being used is 3.14.0 and chromedriver.exe has never been updated since 2 years (2.36.540470). However, chrome browser version in my machine is up to date (84.0.4147.89).
Question: Tests work just fine. Please help me how is this old chromedriver able to work with the newer chrome browser versions ?
Here is the driver initialization code:
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\chromedriver.exe");
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("download.default_directory", "somepath");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver=new ChromeDriver(options);

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?

Chrome options Proxy Bypass List not working

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");

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()

Disable Google Chrome password bubble for WebDriver tests

Given the following code snippet:
case "CHROME":
System.setProperty("webdriver.chrome.driver", DriverPaths.CHROMEPATH);
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
options.addArguments("--disable-notifications");
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--no-proxy-server");
options.addArguments("--enable-automation");
options.addArguments("--disable-save-password-bubble");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
return new ChromeDriver();
Why am I still seeing:
And:
Any ideas?
You will have to use the following commands:
options is your chrome options.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
By passing the capabilities to the chrome driver they will be loaded into chrome.
The DesiredCapabilities.chrome(); will select the correct browser, in this case Chrome.
Chrome asks for the password when your account is set for autologin.
Doing this makes it so that the keyring doesn't load when you
reset/reboot your system.
Chrome is asking for the password to the keyring so it can access
stored information in the keyring. You can view the keyring on your
system by running the command seahorse from a terminal window. You can
also just bypass the asking by closing the window and still get to
your sites without a problem. Some of the security may not load
properly.
However, you can use the following command from a terminal window to
bypass the keyring asking:
google-chrome-stable --password-store=basic
Hope this helps!
YOU CAN SET IT FOR YOUR CHROME LAUNCHER TOO
Courtesy of #Terrance

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.