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?

Elad Benda2
  • 13,852
  • 29
  • 82
  • 157
  • One possible way to handle this https://stackoverflow.com/questions/66560276/how-to-automate-this-downloading-prompt-using-python/66562544#66562544 – Tarun Lalwani Mar 10 '21 at 10:13

5 Answers5

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"

Amey Dahale
  • 750
  • 6
  • 10
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"
Stan E
  • 3,396
  • 20
  • 31
  • 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? – Elad Benda2 Apr 10 '15 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 '15 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? – Elad Benda2 Apr 11 '15 at 09:35
  • As Iknow - there is no. – Stan E Apr 11 '15 at 09:37
  • can you please help me locate this file? I couldn't reach it "Local State" file in profile settings – Elad Benda2 Apr 11 '15 at 09:42
  • ~/Library/Application Support/Google/Chrome – Stan E Apr 11 '15 at 15:45
  • Thanks, but where does it shows which chrome profile this relates to? or is it for all profiles? – Elad Benda2 Apr 11 '15 at 17:19
  • 1
    i added: `"waze":false,"mailto":false,` and yet the popup appears. The webdriver opens an anonymous chrome profile – Elad Benda2 Apr 11 '15 at 17:48
  • two things: (1) in Local stat i don't see it's related to any profile. is it for all profiles? (2) my webdriver uses anonymous chrome- so how can i affect this? – Elad Benda2 Apr 11 '15 at 18:07
  • I have tried it and it works. Have you also tried 2nd variant? – Stan E Apr 11 '15 at 19:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75026/discussion-between-user1065869-and-stanjer). – Elad Benda2 Apr 11 '15 at 19:33
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);
Alex B
  • 66
  • 1
  • 2
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.

Manish Jesani
  • 1,339
  • 5
  • 20
  • 36
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

Pramod
  • 768
  • 1
  • 12
  • 27