6
votes

I'm running an automation on mac and on ubunto (using cucumber, selenium web driver, junit)

during the automation I click a link with non http protocol

an "External protocol request" popup appears.

enter image description here

It blocks my test from testing the rest of the webpage.

How can I bypass it easily?

I have thought maybe to write a jar that does nothing and then register it to this external protocol, but it won't help as this popup will still appear.

Maybe using another browser can help?

Any other suggestions?

5
One possible way to handle this stackoverflow.com/questions/66560276/… - Tarun Lalwani

5 Answers

2
votes

You have 2 possible options.

1) Is running a chrome with a predefined profile, where you have disabled protocol handling manually (via interface or config file) ("Local State" file in profile settings, you should add "waze": false in the appropriate section, you can search for "mailto" to know where is it).

2) Another way is to put put the setting in your tests' constructor before all your tests will start (I'll write an algo, because it depends on your framework and language):

  • navigate to "chrome://settings"
  • press link with css selector "#advanced-settings-expander"
  • press button with css selector "#privacyContentSettingsButton"
  • press label with the needed option using css selector "#handlers-section input[value=block]"
  • press done via css selector "#content-settings-overlay-confirm"
5
votes

I am using chromedriver with selenium and python. I encountered same problem and following code worked for me-

driver.execute_script("window.confirm = function(msg) { return true; }")

prefs = {"protocol_handler.excluded_schemes":{"afp":True,"data":True,"disk":True,"disks":True,"file":True,"hcp":True,"intent":True, "itms-appss":True, "itms-apps":True,"itms":True,"market":True,"javascript":True,"mailto":True,"ms-help":True,"news":True,"nntp":True,"shell":True,"sip":True,"snews":False,"vbscript":True,"view-source":True,"vnd":{"ms":{"radio":True}}}}    

chrome_options.add_experimental_option("prefs",prefs)

Let's say you want to suppress protocol handler popup for links starting with "sip://"
Just add an extra entry as "sip":True in "protocol_handler.excluded_schemes"

1
votes

As for Firefox, the following C# code adds a protocol handler:

firefoxOptions.SetPreference("network.protocol-handler.external.your_custom_protocol", true);
firefoxOptions.SetPreference("network.protocol-handler.expose.your_custom_protocol", true);
firefoxOptions.SetPreference("network.protocol-handler.warn-external.your_custom_protocol", false);

Internet Explorer stores protocol handlers in Registry (works only for local WebDriver):

var baseKey = @"Software\Microsoft\Internet Explorer\ProtocolExecute\your_custom_protocol";
var protocolKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(baseKey, true) ?? Microsoft.Win32.Registry.CurrentUser.CreateSubKey(baseKey);

protocolKey?.SetValue("WarnOnOpen", 0, Microsoft.Win32.RegistryValueKind.DWord);
0
votes

By Using AutoIT(third party tool for windows envrionment). *)Install it(whether 64 bit or 32 bit OS) *) Using Finder tool(AutoIT v3 Window info), Identify the location for "Do Nothing"

Example: Location(700,430)

*)In AutoIT ScriptEditor add the below code MouseClick("left","700,430) and save it as .au3 file format.

*)In your script add this code Runtime.getRuntime().exec("D:\AutoIt\AutoItTest.exe");

*)Run your script.

0
votes

for those who are looking for answer for Javascript-selenium or webdriverJS here is how you can do it. chromeOptions = { 'args': ['--test-type', '--start-maximized', 'use-fake-ui-for-media-stream',], 'prefs': { protocol_handler: { excluded_schemes: { 'iamlegend': false } } }, };

replace 'iamlegend' with your protocol