6

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?

1

5 Answers 5

5

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"

2
  • way better answer
    – Eric B
    May 5, 2017 at 17:01
  • 2
    In the C# Driver you have to use Options.AddUserProfilePreference("protocol_handler.excluded_schemes", new Dictionary<string,bool>{{"ms-excel", false}}); Sep 17, 2018 at 20:52
2

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"
11
  • 1) a) how can I remote webdriver to use specific chrome settings or profile? 1) b) is it also for mac? 2) will it just work without settings change if i just switch to FF? Apr 10, 2015 at 15:33
  • 1) a - via ChromeOptions, how is it - depends on your framework. In java ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir="+userProfile); WebDriver driver = new ChromeDriver(options); 1) b - sure . 2) for ff it should be another option
    – Stan E
    Apr 10, 2015 at 17:47
  • is there a way to suppress it to all profiles? meaning by default no application will handle this protocol, unless specific profile configures explicitly? Apr 11, 2015 at 9:35
  • As Iknow - there is no.
    – Stan E
    Apr 11, 2015 at 9:37
  • 1
    i added: "waze":false,"mailto":false, and yet the popup appears. The webdriver opens an anonymous chrome profile Apr 11, 2015 at 17:48
1

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

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.

1
  • First of all this needs editing. Second, it's clear the asker isn't on the windows environment.
    – nhouser9
    Apr 23, 2016 at 6:24
0

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.