6

enter image description here

Hi. How can I click on 'Allow' button? I really can't find any solution in the internet. I don't want to use c++ hooks or simulate mouse clicks by coordinates. Is there any good way to allow this notification?

new ChromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 2);

doesn't help

JaktensTid
  • 272
  • 2
  • 5
  • 20
  • Did you try to use [alert](https://stackoverflow.com/questions/12744576/selenium-c-sharp-accept-confirm-box) or [chrome options](https://stackoverflow.com/questions/34515328/how-to-set-default-download-directory-in-selenium-chrome-capabilities)? – Sers Feb 18 '19 at 22:42
  • May you be more specific? Which chrome options should I use? Also it is not an alert. It is completely different thing – JaktensTid Feb 19 '19 at 07:48
  • 2
    Maybe by launching Chrome with the `--unlimited-storage` argument? – Florent B. Feb 21 '19 at 12:12
  • @FlorentB. this argument just provides more than 5MB quota for storing browser files. That's it. It does not skip this 'Store files on this device' box. – JaktensTid Feb 21 '19 at 14:39
  • You could use UI automation https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview. You can check before coding anything it's possible if you run the SDK's inspect.exe tool. If this tool shows the dialog box then it's actionable. Of course, this is out of selenium. – Simon Mourier Feb 21 '19 at 22:25
  • Indeed it's totally unrelated to selenium. If you provide me a link that demonstrate the behavior, I can try to publish a sample – Simon Mourier Feb 22 '19 at 10:59
  • @FlorentB. actually you answer works! I don't know why it didn't work for me in the first time, probably I was unattentive and forgot to pass options with this argument to constructor before compiling and running project. I decided to try it one more time after checking chromium source codes # Prevent the infobar that shows up when requesting filesystem quota. '--browser_flag', '--unlimited-storage', May you create the answer and I will give you 100 rep? – JaktensTid Feb 22 '19 at 12:13
  • @Яктенс Тид, I'm glad it worked for you. I don't mind you writing the answer since my comment was just a guess based on the fact that the storage rely on filesystem quotas. – Florent B. Feb 22 '19 at 13:44

3 Answers3

4

Found two solutions:

1) Thanks for @Floren 's answer: C# selenium chromedriver click on Allow store files on this device

There is an argument for Chromium --unlimited-storage

Chromium source code reference:

// Overrides per-origin quota settings to unlimited storage for any
// apps/origins.  This should be used only for testing purpose.
const char kUnlimitedStorage[] = "unlimited-storage";



# Prevent the infobar that shows up when requesting filesystem quota.
    '--unlimited-storage',

C# usage:

var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--unlimited-storage");
var driver = new ChromeDriver(chromeOptions);

2) @Simon Mourier's answer C# selenium chromedriver click on Allow store files on this device

Click on Allow button using .NET UIAutomation

var andCondition = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Allow"));

AutomationElement chromeWindow = AutomationElement.FromHandle(_windowPointer); // IntPtr type
var buttonsFound = chromeWindow.FindAll(TreeScope.Descendants,  andCondition);
if (buttonsFound.Count > 0)
{
   var button = buttonsFound[0];
   var clickPattern = button.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
   clickPattern.Invoke();
}
JaktensTid
  • 272
  • 2
  • 5
  • 20
3

You can't, this is an OS level dialogue, not something inside the DOM.

The way to get around it is by using desired capabilities to configure chrome to not show this dialogue.

I'm going to suggest

ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("download.prompt_for_download", 0);
options.AddUserProfilePreference("settings.labs.advanced_filesystem", 1);

Other potential commands to add the options if AddUserProfilePreference doesn't work would be:

  • AddLocalStatePreference
  • AddAdditionalChromeOption
  • AddAdditionalCapability

For more details about desired capabilities and chrome have a look at:

Ardesco
  • 7,281
  • 26
  • 49
  • C# selenium chromdriver does not have SetExperimentalOptions. I've already tried that. – JaktensTid Feb 21 '19 at 14:38
  • modified it to use C# structure rather than Java one – Ardesco Feb 21 '19 at 15:01
  • Tried that - it does not work. No one of the options. – JaktensTid Feb 21 '19 at 16:44
  • If none of those options work for you then you are stuck. It's an OS level dialogue so not something that Selenium can deal with, The only mechanism that Selenium has for dealing with things like this is DesiredCapabilities. – Ardesco Feb 21 '19 at 22:21
3
        var chromeOptions = new ChromeOptions();
        var downloadDirectory = @"C:\Users\";



        chromeOptions.AddUserProfilePreference("download.default_directory", downloadDirectory);
        chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
        chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");


        chromeOptions.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);

        IWebDriver _driver = new ChromeDriver(chromeOptions);

Can you try with this one ?

Mr.Kim
  • 186
  • 1
  • 10