Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# selenium chromedriver click on Allow store files on this device

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

like image 873
Яктенс Тид Avatar asked Feb 18 '19 21:02

Яктенс Тид


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.


3 Answers

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();
}
like image 103
Яктенс Тид Avatar answered Oct 22 '22 22:10

Яктенс Тид


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:

  • The ChromeOptions documentation
  • This list of command line switches, or the command line switched defined directly in code.
  • The preferences defined directly in code
  • The ChromeOptions class in the Selenium codebase
like image 37
Ardesco Avatar answered Oct 22 '22 23:10

Ardesco


        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 ?

like image 29
Mr.Kim Avatar answered Oct 22 '22 22:10

Mr.Kim