Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically accept Chrome's "Always open these types of links in the associated app" dialogs in Selenium

I'm automating tests using Selenium and C# and I need to open an external app from the browser. The problem is, I always get this notification and it blocks the test execution.

Does anyone know how to deal with this?

Notification screenshot

like image 965
Jose Ferreira Avatar asked Nov 08 '22 10:11

Jose Ferreira


1 Answers

Chrome stores the settings for the acceptance of protocol handlers in the user profile. When running Chrome from Selenium, Chrome doesn't seem to use the standard Chrome user profile by default, and instead uses some default settings that are not persisted.

To get around this, you can launch Chrome from the command line manually and manually specify a new --user-data-dir=c:\foo\bar profile location. (Point it to a new/empty directory and Chrome will populate it for you.)

Using this manually-launched browser, navigate to the page you need to interact with, activate the link, click the "always open" checkbox, and run the program once.

Next, close Chrome and save a copy of the entire new user profile directory. When you run your Selenium tests, make sure to always pass Chrome the same command line options pointing it to that user profile. These settings are now persisted, so the link will open without user intervention in the future. (This question may be of help to feed the right command line args to Chrome.)

For repeatable tests, you will probably want to save a static copy of this profile and redeploy it whenever you launch Selenium.

like image 86
Scott Dudley Avatar answered Nov 15 '22 07:11

Scott Dudley