Selenium ChromeDriver 'Sync is disabled by your administrator' - c#

When I run ChromeDriver and try to sign into my google account I get a message saying 'Sync is disabled by your administrator', 'Your administrator has disabled syncing of your bookmarks, history, passwords, and other settings'.
Then I go to chrome://version/ and in Command Line in the browser it says
--disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources
When I add arguments such as
"--enable-sync" "--enable-web-resources" etc.
C# seems to ignore the arguments because next time I start ChromeDriver, in Command Line it still says those arguments are disabled. How can I get ChromeDriver to have full accessibility functions as if I'm running normal Chrome from my taskbar?

I know another method to what you are trying to do. If you want to "get ChromeDriver to have full accessibility functions as if I'm running normal Chrome from my taskbar?" you should specify to selenium that you want to use a profile that is not temporary.
ChromeOptions options = new ChromeOptions();
options.AddArguments(#"user-data-dir=C:\Users\johndoe\AppData\Local\Google\Chrome\User Data\whateveryouwant");
ChromeDriver driver = new ChromeDriver(options);
Starting chromedriver like this will cause it to remember cookies, extensions, logins, passwords and so on.
It will be like using selenium on your regular chrome browser.

Related

Selenium - start your normal chrome and not chromium

im looking example how can i start my normal google chrome in webdriver c#?
For now i use :
ChromeDriver driver;
public ChromeDriverService chromeDriverService;
chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-infobars");
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
driver = new ChromeDriver(chromeDriverService,chromeOptions);
But it run my chromedriver.exe installed inside project. Can i just run my simple installed chrome? Without download any chromedriver.exe? It's important for me , because some website check if there is opened chromium with chromedriver.exe.
Is it possible to do that?
If you want not just open it but also perform some interaction with your site then you have to deal with Selenium and WebDriver.
You can try Python and undetected-chromedriver which has some workarounds preventing some systems to detect that your browser is running under webdriver control.
Unfortunately, it's the chromedriver.exe that lets you interact with Chrome so, without the driver, you wouldn't be able to interact with the actual browser.
If your issue is with chromium, try driving Mozilla with GeckoDriver
Selenium always uses chromedriver.exe for interacting with Chrome, I think you mean you want to load your default data directory. You can add a chrome option for this purpose:
chromeOptions.AddArguments(#"C:\Users\<your user name>\AppData\Local\Google\Chrome\User Data")
Take care, any other chrome must not be running that time with the same data directory. Like you may have run for your personal use.
You can also create a data directory somewhere else if you just want to show some realistic behavior to a website. But some websites are smart enough so it does not work every time.

I'm trying to use my chrome profile with webdriver but it says its already attached

You can see the code which I am using below to use another profile with webdriver. I'm needing to know how this is done since I want to be able to load my current chrome profile in to webdriver
options.AddArguments(String.Format(
"--user-data-dir=\"{0}\"", #"C:\Users\zacha\source\repos\Trial Bot - Test\Trial Bot - Test\bin\Debug\User Data"));
driver = new ChromeDriver(#"C:\Users\zacha\source\repos\Trial Bot - Test\Trial Bot - Test\",options);
Error when ran:
OpenQA.Selenium.WebDriverException: 'unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at "C:\Users\zacha\source\repos\Trial Bot - Test\Trial Bot - Test\bin\Debug\User Data" is still attached to a running Chrome or
This error message...
OpenQA.Selenium.WebDriverException: 'unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at "C:\Users\zacha\source\repos\Trial Bot - Test\Trial Bot - Test\bin\Debug\User Data" is still attached to a running Chrome
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser using the Chrome Profile through the argument --user-data-dir as the desired Chrome Profile is still in usage by a running google-chrome browsing instance.
Possibly the Chrome Profile which you are trying to access through Selenium driven ChromeDriver initiated Google Chrome Browsing Context is the same profile you are accessing manually for your other/debugging tasks i.e. the Trial Bot - Test profile. So, the Chrome Profile remains locked and not accessable by ChromeDriver. Hence you see the error.
As a solution try to use different Chrome Profiles for different tasks.

Unable to hide "Chrome is being controlled by automated software" infobar within Chrome v76

After updating Chrome to version 76, I cannot figure out how to hide the "Chrome is being controlled by automated software..." notification overriding some controls on the page.
The latest stable release of ChromeDriver is indeed 76.0.3809.68.
The following code worked with Chrome 75 and ChromeDriver 74.
var options = new ChromeOptions();
options.AddArgument("--test-type");
options.AddArgument("--disable-extensions");
options.AddArguments("disable-infobars");
options.AddArguments("--disable-notifications");
options.AddArguments("enable-automation");
options.AddArguments("--disable-popup-blocking");
options.AddArguments("start-maximized");
var driver = new ChromeDriver(driverLocation, options, ScriptTimeout);
As of 1 Aug 2019 - You can send the excludeswitch - enable-automation to hide the message. and to disable pop up 'Disable developer mode extensions' set
useAutomationExtension=false . Refer for useAutomationExtension
Tested on : Windows 10
Version 76.0.3809.87 (Official Build) (64-bit)
ChromeDriver 76.0.3809.68
--enable-automation : Inform users that their browser is being controlled by an automated test Reference
"goog:chromeOptions": {
"excludeSwitches": [ "enable-automation" ],
"useAutomationExtension": false
}
In C# :
To disable pop up "Disable developer mode extensions" and automation info-bar message .
options.AddExcludedArgument("enable-automation");
options.AddAdditionalCapability("useAutomationExtension", false);
In JAVA :
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
In Python :
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
In Protractor :
Add below capabilities in conf.js/conf.ts
capabilities: {
'browserName': 'chrome',
"goog:chromeOptions": {
"excludeSwitches": [ "enable-automation" ],
"useAutomationExtension": false
}
},
Chromium team earlier introduced the infobar Chrome is being controlled by automated test software to disable Developer mode extension popup within Chrome Browser through this commit.
As per the discussion Flakiness due to Chrome automation infobar (Chrome 57+) with the addition of the infobar to display if a session is being controlled by an automated test within Chrome it was observed that the presence of Chrome automation infobar Chrome is being controlled by automated test software intermitently caused the click() function to fail. During the tests, when the the infobar was removed by passing disable-infobars within chrome_launcher.cc then the above tests runs as expected without any issues. gmanikpure#chromium.org confirmed that the culprit was the changelog:
Add an infobar if a session is being controlled by an automated test.
This infobar is only displayed if the browser is launched with the --enable-automation switch. It also disables the developer mode extensions warning bubble.
TEST=launch with and without --enable-automation, and check for presence of automation infobar
It was observed that, during a click the infobar animation occurs and we got flaky results. So Chromium team needed to detect this change somehow and recompute the position. The actual problem was, if a Page.frameResized occured we can invalidate the results of some operations and retry (e.g. get element position) but there were other operations that can modify the page, such as mouse clicks. It's possible that a mouse click (which involves a mousemove, mousedown and a mouseup event) can have a resize event in the middle.
Accordingly, Chromium team released a revision through this commit:
Disable info bar animations during automated testing.
Since then Chrome user, to disable the infobar started using:
Java:
options.addArguments("disable-infobars");
Python:
options.add_argument("disable-infobars")
C#:
option.AddArguments("disable-infobars");
Now in the discussion Chrome is being controlled by automated test software infobar doesn't gets suppressed despite using disable-infobars argument Chromium team member triciac#chromium.org clearly mentioned:
As of v 76, the ability to suppress the infobar was moved from command line options to Enterprise Policy settings for Chrome.
The change was already mentioned in the Release Notes and Chrome Enterprise release notes as follows
--disable-infobars is no longer supported
Chrome will no longer support the --disable-infobars flag, which was used to hide pop-up warnings
from Chrome Browser. To support automated testing, kiosks, and automation, the
CommandLineFlagSecurityWarningsEnabled policy was added to allow you to disable some security
warnings.
So, from Chrome v76.x onwards --disable-infobars flag is officially deprecated.
Conclusion
The policy is not an option or a capability that is set when ChromeDriver or Chrome is launched as security policies are typically managed by your corporate IT department. Hence usage of disable-infobars have been deprecated.
A small Hack
The --disable-infobars flag can still removed from Chrome v76.x using these 2(two) ExperimentalOption:
Excluding the switches for enable-automation
Setting useAutomationExtension to False
Implementations
Here are the implementations:
Java:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");
Python:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
Outro
As per the article CommandLineFlagSecurityWarningsEnabled:
Enable security warnings for command-line flags
Supported on: Google Chrome (Linux, Mac, Windows) since version 76
Description: If disabled, prevents security warnings from appearing when Chrome is launched with some potentially dangerous command-line flags.
If enabled or unset, security warnings are displayed when some command-line flags are used to launch Chrome.
On Windows, this policy is only available on instances that are joined to a Microsoft Active Directory domain or Windows 10 Pro or Enterprise instances that are enrolled for device management.
This will work in C#:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--incognito");
chromeOptions.AddExcludedArgument("enable-automation");
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
To hide "Chrome is being controlled by automated test software" infobar in C# for Chrome v76:
var chromeOptions = new ChromeOptions();
...
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
chromeOptions.AddExcludedArgument("enable-automation");
...
var driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), chromeOptions, commandTimeout);
You can use --app=desired_address_without_brackets flag, e.g. --app=https://google.com. Works in Chrome 80.
Of course it works only if it's acceptable for your project to be launched in App mode and you have a page link you can insert there. See this answer of mine for a little more info.
You can also use --test-type command line flag, which removes such infobars too.
Attention! In very rare cases it causes strange things like muting page sound! So I'm not sure I should recommend it in the first place.
In Ruby, for the selenium-webdriver gem, which is often used with Capybara, use ::Selenium::WebDriver::Chrome::Options#add_option('excludeSwitches', ['enable-automation']).
For example:
Capybara.register_driver :selenium_chrome do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.add_option 'excludeSwitches', ['enable-automation']
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end
Another option in Ruby for me was:
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: chrome_options)
end
def chrome_options
options = Selenium::WebDriver::Chrome::Options.new
options.add_option 'excludeSwitches', ['enable-automation']
options.add_argument('incognito')
options.add_argument('disable-geolocation')
options.add_argument('ignore-certificate-errors')
options.add_argument('disable-popup-blocking')
options.add_argument('disable-web-security')
options.add_argument('--disable-infobars')
options.add_argument('disable-translate')
options
end
Apparently you can use the CommandLineFlagSecurityWarningsEnabled chrome policy - https://www.chromium.org/administrators/policy-list-3#CommandLineFlagSecurityWarningsEnabled
On Linux I was able to create a file at /etc/opt/chrome/policies/managed/managed_policies.json with the contents: {"CommandLineFlagSecurityWarningsEnabled": false} and this disabled the warning.
On Windows 10 Pro when I set the Chrome group policy "Enable security warnings for command-line flags" to disabled (see https://support.google.com/chrome/a/answer/187202) and check the registry at Software\Policies\Google\Chrome\CommandLineFlagSecurityWarningsEnabled for a value of 0x00000000 it doesn't work for me to disable this warning. Maybe it will for you? Wondering if someone else can help shed light on why it won't work on Windows

Geckodriver 0.16.0 start firefox with flashplayer

Since geckodriver v0.16.0 flashplayer is disabled by default.
Is there any possibility to start firefox with enabled flashplayer?
I'm using C#. My code right now:
var profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("selenium"); //created firefox user named selenium
profile.SetPreference("plugin.state.flash", 1);
Code bellow doesn't work for me:
profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", true);
When I use this one:
profile.SetPreference("plugin.state.flash", 1);
firefox is asking if I want to enable flashplayer, and than refreshes page (with all inputs filled previously - so i got empty fields).
If I select "allow and remember", next time I start this code nothig is saved. I'm getting the same situation.
I found solution there:
How to enable Adobe Flash in FireFox Selenium webdriver with FirefoxProfile
If I replaced profile.setPreference("plugin.state.flash", 1); to profile.setPreference("plugin.state.flash", 2); it stopped to asking me if I want to enable flash player.
Here is the solution for you:
With Selenium 4.3.0, gecko driver v0.16.0 & Mozilla Firefox 53.0 this code works well with myfreecams.com.
It is worth mentioning that the default Firefox profile is not very automation friendly. When you want to run automation reliably on a Firefox browser it is advisable to make a separate profile. Automation profile should be light to load and have special proxy and other settings to run good test. You should be consistent with the profile you use on all development and test execution machines. If you used different profiles everywhere, the SSL certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently on the machines.
So, Create a New Firefox profile and use the same in the Test script involves three steps process. First you need to Start the Profile Manager, second is to Create a New Profile and third is to use the same profile in Test scripts. Let's assume we created a new FirefoxProfile by the name "debanjan".
Use the following code to open http://www.myfreecams.com/ with your new FirefoxProfile "debanjan":
String driverPath = "C:\\Utility\\BrowserDrivers\\";
//Mozila Firefox
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
FirefoxDriver driver = new FirefoxDriver(dc);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.navigate().to("http://www.myfreecams.com/");
PS: This code is in Java so you may have to convert it into C# format.
Let me know, if this helps you.

How to launch multiple instances of Firefox portable using Selenium FirefoxDriver

I use selenium FirefoxDriver in my tests and I run these tests parallel - in each thread is running separated Firefox instance. Everything works fine when I use normal FireFox, but if I want to run these tests with Firefox portable, the first instance launch successful, but second, third, etc... fails with this error:
Your Firefox profile cannot be loaded. It may be missing or inaccessible.
This is how I launch Firefox from code:
var profile = new FirefoxProfileManager().GetProfile("default");
var firefoxBinary = new FirefoxBinary("Path to FireFoxPortable.exe");
_driver = new FirefoxDriver(firefoxBinary, profile);
Any ideas what I am doing wrong?
Thanks.
The Firefox driver is trying to launch Firefox using a profile that is already in use. This is not possible as a profile can only be used once. The reason why it appears to be working while launching Firefox manually multiple times is because Firefox will reuse the existing running Firefox process with the already loaded profile.
Based on this information the solution to your problem is either 1) have the Firefox driver launch Firefox with unique/new profiles, 2) change your code so that only one instance of the Firefox driver is required.
To launch Firefox with multiple instances, use: firefox.exe -P "My Profile" -no-remote. Do not that the -no-remote parameter should not be used with the first profile launched, which in your case will be the "default" profile. More on this here: http://kb.mozillazine.org/Opening_a_new_instance_of_Firefox_with_another_profile.
To launch Firefox Portable with different profiles, if the previous commands are not applicable for Firefox Portable, follow the instructions here: http://portableapps.com/support/firefox_portable#second_profile.

Categories

Resources