Getting chrome.exe popup opened while executing selenium scripts - google-chrome

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

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.

How to handle .jnlp download file operation in Chrome 53 from Selenium Webdriver

I am trying to write code in Selenium Webdrvier 3.0 + Java 1.8 + Chrome 53 for an application which needs to download and execute a .jnlp file after invoking a get(url). I am not sure whether this could be handled in Selenium webdriver or not?
As I am new to selenium any help or guidance for handling these Windows Pop will be really helpful for me.
Below is the piece of code :
if(browser.contains("CHROME") || browser.equalsIgnoreCase("chrome"))
{
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
options.addArguments("--disable-extensions");
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setCapability(ChromeOptions.CAPABILITY, options);
}
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
browserDriver = new RemoteWebDriver(new URL(nodeAddress), capability);
browserDriver.manage().timeouts().pageLoadTimeout(1000, TimeUnit.SECONDS);
browserDriver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
browserDriver.manage().window().maximize();
browserDriver.get(applicationUrl);
logger.info("WebDriver successfully defined with Session ID:" + browserDriver.getSessionId() + ", Page Title:" + browserDriver.getTitle() + " and URL: " + browserDriver.getCurrentUrl());
Image attached : http://i.stack.imgur.com/esfpk.jpg
The button you are trying to click is part of Chrome's UI and not part of the webpage so Selenium cannot interact with it. From the googling I've done, this is apparently an issue that people have reported as a bug and there is no consistent workaround.
I've found a workaround via Selenium + Python (but similar thing should be feasible in Java too). In Python I just click programmatically on the notification in Chrome UI to allow downloading and installation of the jnlp file (with help of win32api and win32con - I needed it for Win only). See details here
Webscraping is now much easier for me :)

Selenium Chrome suppress/dismiss client certificate selection dialog

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

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)