Selenium Chrome suppress/dismiss client certificate selection dialog - google-chrome

How can I suppress or automatically dismiss the client certificate selection dialog with selenium (chrome driver)?
I can't use this certificate, because it is stored on a chip card and I would have to enter a PIN. If no card is available, our website used a credential based login and I want to test this.

I found a solution to this problem:
You must use chrome parameter - AutoSelectCertificateForUrls
Add this to the windows registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\AutoSelectCertificateForUrls\1 = "{"pattern":"https://yoursite.com","filter":{}}"

In linux you need this file set:
$HOME/etc/opt/chrome/policies/managed/auto_select_certificate.json
With this content:
{
"AutoSelectCertificateForUrls": [ "{\"pattern\":\"*\",\"filter\":{}}" ]
}
With this set it should allow every installed client certificate automatically.
Detailed article about how to solve it in C# with Docker can be found in an article I wrote here:
https://sgedda.medium.com/running-selenium-with-chromedriver-together-with-client-certificate-set-in-headful-mode-with-net-a79bde19e472

Try to launch chrome using "--ignore-certificate-errors" and "--ignore-urlfetcher-cert-requests" arguments.
ChromeOptions opts = new ChromeOptions();
opts.addArguments("ignore-certificate-errors","ignore-urlfetcher-cert-requests");
WebDriver driver = new ChromeDriver(opts);
driver.get("http://www.google.com");
System.out.println("Title:" + driver.getTitle());

Try below code. It worked for me:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--ignore-urlfetcher-cert-requests");
webDriver = New ChromeDriver(chromeOptions);

Related

Looking For Ways To Update Chromedriver Options

I have an application that tests various custom Chrome extensions with various sites. My current code looks like this
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("extension1.zip"));
WebDriver driver = new ChromeDriver(options);
driver.get("https://site1.com");
// Evaluate page
driver.quit();
options = new ChromeOptions();
options.addExtensions(new File("extension2.zip"));
driver = new ChromeDriver(options);
driver.get("https://site2.com");
// Evaluate page
driver.quit();
There is a lot of overhead associated with opening and closing the browser. Over time, the application gets slower and slower. I would like to be able to remove and add extensions without opening and closing the driver and the browser. Each site needs to be evaluated with only one of the extensions. Currently, I'm evaluating 8 sites and 8 extensions, but the number of sites and extensions will grow over time.
Any help is appreciated.
See if this will remove previously added extensions:
options.addArguments("--disable-extensions");
The entire code is
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);

Selenium Java ChromeDriver - How to disable attached sites

When loading a web page, it sometimes keep hanging on loading sites like "google analytics", "gstatic.com", etc.
It sometimes hangs forever.
Is there a way to disable this behavior?
Working with Selenium 3.4.0 along with the latest chromedriver 2.29 & latest Google Chrome 58.0 to restrict the loading of the sites you can take help of pageLoadStrategy through DesiredCapabilities Class as follows:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
DesiredCapabilities c1 = DesiredCapabilities.chrome();
c1.setCapability(ChromeOptions.CAPABILITY, options);
c1.setCapability("pageLoadStrategy", "none");
WebDriver driver1 = new ChromeDriver(c1);
Navigation navigate = driver1.navigate();
navigate.to("https://gmail.com");
Disclaimer:
Using this capability you cannot be sure if the HTML DOM have completely loaded or not for you to continue working with the WebElements present on that Webpage.
Let me know if this Answers your Question.

Getting chrome.exe popup opened while executing selenium scripts

I'm getting a popup opened from location C:\Program Files\Google\Chrome\application\chrome.exe while executing selenium webdriver scripts in chrome browser.
This one is throwing the error as session timed out.
Note: The same codebase is working fine in other machine.
Can you please help me out to get this sorted.
The code I am using is as below:-
var arr = new string[7] {
"--start-maximized", "--ignore-certificate-errors", "--disable-popup-blocking", "--disable-default-apps", "--auto-launch-at-startup", "--always-authorize-plugins", "--user-agent= " + FrameGlobals.userAgentValue
};
chromeCapabilities.AddArguments(arr);
WebDriverObj = new ChromeDriver(chromeCapabilities);
This is how i'm initiating the chrome browser. not mentioning any version inside codebase.
enter image description here
Thanks in advance.
Hema
You can add all your argument one by one and then pass it to the Chromedriver as below:-
WebDriver driver=null;
System.setProperty("webdriver.chrome.driver","./src//lib//chromedriver");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArgument("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--allow-running-insecure-content");
capabilities.setCapability("chrome.binary","./src//lib//chromedriver");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver.get("https://www.google.com/");
Replace your argument with above-mentioned arguments
Hope it will help you :)

play DRM content in chrome driver

I'm writing some selenium tests for a HTML5 player playing DRM content, the player works fine in Chrome when I test it manually, but nothing is loaded or played in the latest chrome driver if I run my test cases.
Is it because of the drm content isn't authorized to play in chrome driver or something else?
I have no issues running tests for other functions written in selenium.
Any ideas?
Chromedriver launches Chrome with --disable-component-update switch by default, which disables the NaCl (Native Client) support, which is in turn required to load DRM modules (e.g. Widevine Modular DRM).
To get around this, you need to tell the driver not to launch Chrome with this switch, by building the driver with excludeSwitches option, specifying disable-component-update parameter. For example (JS):
var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");
var capabilities = new webdriver.Capabilities.chrome();
var chromeOptions = {
'args': ['--user-data-dir=C:/ChromeProfile'], // start with pre-configured Chrome profile
'excludeSwitches': ['disable-component-update'] // stop breaking Native Client support
};
capabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder().
withCapabilities(capabilities).
build();
driver.get('http://...');
Or using Python bindings:
from selenium import webdriver
def buildDriver():
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['disable-component-update'])
options.add_argument('--user-data-dir=C:/Temp/ChromeProfile')
return webdriver.Chrome(chrome_options=options)
Hope that helps..
-- ab1
Issue 886: Enabled PNaCl Components in ChromeDriver - Enhancement
If you cannot get #Chainik's answer to work, try this out. It worked for me.
As per https://bugs.chromium.org/p/chromedriver/issues/detail?id=1140 you can work around this issue by doing a few things.
manually start chrome from terminal/command prompt with these command line arguments --
google-chrome --user-data-dir=/path/to/any/custom/directory/home/user/Desktop/Chromedir --profile-directory="Profile 1" --remote-debugging-port=7878
make sure "Profile 1" is already existing in the same --user-data-dir (make usre Profile 1 has necessary chrome://components/ to run Netflix when launched manually)
you can use any free port in place of 7878
verify that http://localhost:7878 is running and returns value.
now connect to the remote-debugging-port=7878 via chromedriver with code below
Verify chrome://components/
I put mine into a .bat file, but you could do the same for a bash script or whatever:
C:/Program Files (x86)/Google/Chrome/Application/chrome.exe --user-data=c:/temp/chromeprofile --profile-directory="Profile 1" --remote-debugging-port=7878
Then set the debugger address in your code to use the browser:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
cr_options = Options()
# This line is where the "magic" happens.
cr_options.add_experimental_option('debuggerAddress','127.0.0.1:7878')
browser = webdriver.Chrome(chrome_options=cr_options)
browser.get('https://www.google.com')
browser.get('chrome://components/')
I'm post a java version of Chainik's answer as a reference for those using Java, please let me know if there's anything wrong.
ChromeOptions options = new ChromeOptions();
List<String> list = new ArrayList<String>();
list.add("disable-component-update");
options.setExperimentalOption("excludeSwitches", list);
options.addArguments("user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/Default");
java.lang.System.setProperty("webdriver.chrome.driver","/usr/bin/chromedriver");
Webdriver driver = new ChromeDriver(options);
Here is an article about chromedriver capabilities and options.
This is late but might help someone else. I was able to get around this and play videos by not using a headless browser.
In Python,
options = Options()
options.headless = False
webdriver.Chrome(executable_path='path/to/chromedriver', options=options)

Automatic translation is disabled when using selenium in chrome

When I open a webpage which is in foreign language using selenium webdriver in chrome, it isn't automatically translated to English. How do I over ride this behavior?When I manually open the same page it is being translated automatically. Is there some kind of configuration in chrome driver that disables automatic translation? Is there a way to enable the same?
Did you try loading your Chrome WebDriver using you current user profile ?
I think that should do the trick for you.
String userProfile= "C:\\Users\\<your user dir>\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\";
ChromeOptions objOptions = new ChromeOptions();
objOptions.addArguments("user-data-dir=" + userProfile);
objOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(objOptions);
driver.navigate.to("<your url here>");