How to provide OperaWebDriver on c# use Selenium WebDriver - c#

How to provide OperaWebDriver on c# use Selenium WebDriver
IWebDriver aDriver = new OperaDriver("path_to_operadriver.exe);
I have exception :
System.InvalidOperationException : unknown error: cannot find Opera
binary (Driver info: OperaDriver=0.2.0 )

Using setBinary gives me an error. I am able to resolve it by using this:
options.BinaryLocation = #"/path/to/opera";
Similarly for chrome as well.

You've got to download opera chromium driver.
Here's a snippet how it should work:
DesiredCapabilities capabilities = DesiredCapabilities.opera();
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/opera");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

Related

Disabling 'Save address' chrome browser popups using C# Selenium

Need help to block save address pop up coming in chrome browser while executing selenium c# automation scripts.
Following all options already tried but no luck.
IWebDriver driver;
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("--disable-single-click-autofill");
chromeOptions.AddArgument("--disable-popup-blocking");
chromeOptions.AddExcludedArgument("--disable-infobars");
chromeOptions.AddAdditionalChromeOption("useAutomationExtension", "false");
chromeOptions.AddArgument("--disable-notifications");
chromeOptions.AddUserProfilePreference("disable-popup-blocking", "true");
new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
driver = new ChromeDriver(chromeOptions);
I was able to turn off the Save Address prompt using AddUserProfilePreference. It is called "autofill.profile_enabled". You can just add it to your ChromeOptions and pass those options in when instantiating the driver.
I got the name from this Reddit post:
https://www.reddit.com/r/selenium/comments/yicwf0/chromium_how_to_disable_save_and_autofill_address/
ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
options.AddArgument("test-type");
options.AddArgument("disable-notifications");
options.AddUserProfilePreference("autofill.profile_enabled", false);
IWebDriver webDriver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options, TimeSpan.FromSeconds(240));

Selenium ChromeDriver 101.0.4951.41 cannot start DevTools

Hi. I tried upgrade my chromedriver to 101.0.4951.41 today and it sudden keep prompt this error to me. Anything I missed or what I should add for new version?
And this is my code:
options.AddArgument("start-maximized");
options.AddArgument("--disable-extensions");
options.AddArgument("--disable-blink-features");
options.AddArgument("--disable-blink-features=AutomationControlled");
options.AddArgument("--disable-gpu");
options.AddArgument("--no-sandbox");
options.AddArgument("--allow-running-insecure-content");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--disable-background-networking");
options.AddExcludedArguments(new List<string>() { "enable-automation" });
options.AddUserProfilePreference("credentials_enable_service", false);
options.AddUserProfilePreference("password_manager_enabled", false);
ChromeDriverService chromeDriverService=ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
IWebDriver Driver = new ChromeDriver(chromeDriverService, options);
IDevTools devTools = Driver as IDevTools;
IDevToolsSession session = devTools.GetDevToolsSession();
Fixed by adding the protocol version (i.e.)
using DevTools = OpenQA.Selenium.DevTools.V96;
:
:
IDevTools devTools = webDriver as IDevTools;
IDevToolsSession session = devTools.GetDevToolsSession(96);
Had a similar issue and it seems in versions above and equal 100 need to have the remote-debugging-port argument set.
Add this to args:
"--remote-debugging-port=9222"
This opens the devtools for me when I open the driver itself. I tested it on version 101.0.4951.41 so it should work fine for you. (no remote debugging port required)
options.AddArgument("--auto-open-devtools-for-tabs");
Apparently the new version of chromedriver (101.0.4951.41) is not compatible with old version of DevTools
I can solved this issue updated Selenium.WebDriver to 4.1.1 and used "OpenQA.Selenium.DevTools.V101.Network"

Enable downloads in headless chrome with Selenium Grid

The only way that I've found to enable downloads in Headless Chrome is with the following code:
var param = new Dictionary<string, object>();
param.Add("behavior", "allow");
param.Add("downloadPath", $"C:\\Users\\{Environment.UserName}\\Downloads\\");
driver.ExecuteChromeCommand("Page.setDownloadBehavior", param);
However, when using Selenium Grid, the driver must be initialized as RemoteWebDriver:
driver = new RemoteWebDriver(new Uri(url), options);
RemoteWebDriver doesn't have the ExecuteChromeCommand method and it can't be cast to ChromeDriver ((ChromeDriver)driver throws an exception).
Therefore, how can I enable downloads in headless chrome when using Selenium Grid?

Selenium Webdriver c# : Getting "The path is not of a legal form." while initializing FirefoxProfile

I am using below mentioned code to initialize a firefox driver with service, options and timeout.
var Service = FirefoxDriverService.CreateDefaultService(RunConfig.DriverPath);
Service.HideCommandPromptWindow = RunConfig.HideDriverCommandPromptWindow;
var Options = new FirefoxOptions();
if (!string.IsNullOrWhiteSpace(RunConfig.PathToBrowserBinary))
Options.BrowserExecutableLocation = RunConfig.PathToBrowserBinary;
Options.Profile = new FirefoxProfile();
Options.Profile.SetPreference(Preference.Name,PathToDownloadFolder));
Options.Profile.SetPreference(Preference.Name, Preference.Value);
return new FirefoxDriver(Service, Options, TimeSpan.FromSeconds(90));
But it gives me an error that The path is not of legal for while initializing firefox profile
Solved it. The problem was the seleniumwebdriver dll I was using is present in some other project. Adding the selenium webdriver and support dll to the current project worked.

ChromeOptions and DesiredCapabilities relations in Selenium and C#

I've been searching for the correct documentation on how to use ChromeOptions and DesiredCapabilities in the atmosphere of Selenium and C#, but since it's all open sourced, I only find suggestions (and they are not helping sometimes). My question today is how to setup the correct relation between ChromeOptions and DesiredCapabilities. Seems like I'm doing everything correctly, but still getting System.InvalidOperationException: unknown error:cannot parse capability: chromeOptions from unknown error: unrecognized chrome option:Arguments My code is following:
private static ChromeOptions Ops()
{
var options = new ChromeOptions();
options.AddArgument("--no-startup-window");
options.BinaryLocation = #"C:\path\path\path\chromedriver.exe";
return options;
}
private static DesiredCapabilities Caps()
{
DesiredCapabilities caps = new DesiredCapabilities();
caps.SetCapability(CapabilityType.BrowserName, "chrome");
caps.SetCapability(ChromeOptions.Capability,Ops().ToCapabilities());
return caps;
}
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), Caps());
Can't find a place where incorrect Arguments are passing. Has anybody faced the same issues? This is ChromeDriver version 2.28 and selenium WebDriver v 3.3.0 Google Chrome browser version is 52.
You don't need to set the browser name; ChromeOptions does that for you.
According to this comment
The .NET bindings are moving toward a pattern where DesiredCapabilites should not be
used directly, even with RemoteWebDriver. To facilitate that, the ChromeOptions class
has a ToCapabilities() method
And there's this comment
Much like --disable-javascript, the chromedriver will not work if you use --no-startup-window.
It needs to launch a window to establish the connection with the AutomationProxy.
So that gets us to this:
var options = new ChromeOptions();
options.BinaryLocation = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), options.ToCapabilities());
However, are you actually running a grid? If you're testing on a single machine it's even simpler:
IWebDriver driver = new ChromeDriver();

Categories