I am using ChromeDriver in C# code console app, everything works well as I expect. But I need to hide the messages/logs from the chrome driver. Used below code. Still seeing the messages like:
Starting ChromeDriver 2.41.578737
(49da6702b16031c40d63e5618de03a32ff6c197e) on port 51929
Only local connections are allowed.
DevTools listening on
ws://127.0.0.1:51932/devtools/browser/09ed1c7f-c33a-4f76-990b-943c6837d8d8
ChromeOptions options = new ChromeOptions();
var chromeDriverService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
chromeDriverService.HideCommandPromptWindow = true;
chromeDriverService.SuppressInitialDiagnosticInformation = true;
options.AddArgument("headless");
options.AddArgument("--silent");
options.AddArgument("log-level=3");
IWebDriver driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),options);
I did suppress the logs by adding "options.AddArgument("log-level=3");". I am trying to avoid seeing below in my console, I need to suppress these messages too:
Starting ChromeDriver 2.41.578737
(49da6702b16031c40d63e5618de03a32ff6c197e) on port 51929
Only local connections are allowed.
DevTools listening on
ws://127.0.0.1:51932/devtools/browser/09ed1c7f-c33a-4f76-990b-943c6837d8d8"
You need to pass the chromeDriverService in the ChromeDriver constructor:
IWebDriver driver = new ChromeDriver(chromeDriverService, options);
Related
I am trying to hide command prompt window when starting selenium chrome, but I can't figure it out.
Here is my code:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--headless");
var browser = new ChromeDriver(driverService, chromeOptions);
But it crash on: System.InvalidOperationException: 'session not created: This version of ChromeDriver only supports Chrome version 85
I tried to manually add path to driver but It crash's also.
Different code I used
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--headless");
chromeOptions.BinaryLocation = "C:\\Users\\TriX\\Downloads\\chromedriver_win32";
var browser = new ChromeDriver(driverService, chromeOptions)
Now it crash on: OpenQA.Selenium.WebDriverException: 'unknown error: Failed to create Chrome process.'
Thanks for help I am completely lost :(
I tried different codes as shown, but without success.
Thanks to #r000bin i managed to resolve the problem. I also find out that I installed outdated version of ChromeDriver. So, I downloaded the correct one and it started to work.
I had old ChromeDrive nuget version
Downloaded the new one and uninstalled old one
Started to work :)
We use ChromeDriver in C# to connect to existing instances of Chrome that have the remote debugging port 9222 set. Here is how we connect:
var svc = ChromeDriverService.CreateDefaultService(path);
ChromeOptions options = new ChromeOptions();
options.DebuggerAddress = "127.0.0.1:9222";
var driver = new ChromeDriver(svc, options);
var url = driver.Url;
The problem is that the value of driver.Url is not what it used to be when using ChromeDriver version 88.
At that point and all earlier versions, driver.Url was the value of the URL for the current active tab in Chrome. So if Chrome had five tabs open and tab 4 is active, the Url was that of tab 4. And that made sense.
Once we upgraded to version 90 that is no longer the case. It appears that the value of Url is... well it's not clear. Sometimes the last active tab, sometimes some other tab, sometimes the first. I do not see a pattern.
Is this an error in ChromeDriver? In the past, whatever was the active tab was the one that driver.Url yielded. Now it's indeterminate which wreaks havoc with our code.
Update: If I have two tabs open, then the driver.Url and driver.Title are for the tab that was just prior active. So always the other tab. With 3 tabs it may be the 2nd to the last active tab. This feels like a off-by-one error within an internal array of tabs.
I had the same problem. I solved it using the method suggested here
ChromeDriverService driverService =
ChromeDriverService.CreateDefaultService();
var options = new ChromeOptions();
options.DebuggerAddress = "127.0.0.1:9222";
var driver = new ChromeDriver(driverService, options);
driver.SwitchTo().Window(driver.WindowHandles[0]); // Switch to the recently opened tab
MessageBox.Show("driver.Url: " + driver.Url);
I apologize in advance if the following question seems to be very basic, but I am very new to Selenium and I really need help.
So what I am trying to do is, I am trying to open a window popup but Chrome browser is blocking it by its own.
I am used the following code:
ChromeOptions options = new ChromeOptions();
options.AddUserProfilePreference("disable-popup-blocking", "true");
IWebDriver driver = new RemoteWebDriver(new Uri("http://path/to/selenium/server"), options.ToCapabilities());
But its throwing me an exception saying:
Unexpected error. System.Net.WebException: The remote name could not be resolved: 'path'.
I have tried this, But didn't help though gave me a rough idea.
Can someone please help?
(Reference: Unblocking popup using Selenium using C#)
Try as below :-
ChromeOptions options = new ChromeOptions();
chromeOptions.AddArgument("--disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability(ChromeOptions.Capability, options);
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);
Edited :- if you want to use ChromeDriver instead of RemoteWebDriver try as below :
ChromeOptions options = new ChromeOptions();
chromeOptions.AddArgument("--disable-popup-blocking");
IWebDriver driver = new ChromeDriver(#"C:\path\chromedriver", options);
Hope it works...:)
I have a Selenium suite which has 150 test cases. The test has to run in Incognito mode in Chrome Browser.
I am able to launch the browser in incognito Mode. But the issue is the browser is not getting maximized ( say for 10 test cases and for remaining 140 test cases the browser launches in maximized mode) , though there is a code to maximize the browser.
As a result of this, some of the test fails ( All 10 test ).
Below is my code
desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
break;
Is there a way to ensure that the browser always (100%) launches in maximised mode.
The click operation fails when the browser is not maximised.
System.InvalidOperationException: unknown error: Element is not clickable at point (886, 466). Other element would receive the click:
For this reason, I want to run in maximised mode. In maximised mode, I am not getting this error. Please help .
Thanks
Try this code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--incognito");
IWebDriver driver = new ChromeDriver("C://",options);
It works for me
Could do something like this:
desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
webDriver.Manage().Window.Maximize();
break;
It will need to be after the webDriver opens up, but it will maximize the window for you.
Try this instead, I have tested and should be fine
var caps = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument(#"--start-maximized");
caps.SetCapability(ChromeOptions.Capability, options);
var webdriver = new ChromeDriver(options);
webdriver.Navigate().GoToUrl("http://yourURL.com");
webdriver.Manage().Window.Maximize();
An alternative would be to set the initial size:
options.AddArgument("--window-size=1024,768");
You could also set some extreme values. The window should then have the size of the screen since the OS limits it (at least on Windows) :
options.AddArgument("--window-size=32000,32000");
I created a console application (with target: .Net Framework 4) and added the next references:
Selenium.WebDriverBackedSelenium.dll
ThoughtWorks.Selenium.Core.dll
WebDriver.dll
WebDriver.Support.dll
static IWebDriver driver = null;
if (driver == null)
{
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
driver = new ChromeDriver(#"C:\selenium\net40", options);
// it opened a new window (about:blank)
}
driver.Navigate().GoToUrl("http://www.facebook.com");
but nothing is happen.
I use: ChromeDriver 26.0.1383.0
and my chrome browser version is: 29.0.1547.62 m
this is the command line:
Started ChromeDriver
port=1866
version=26.0.1383.0
log=C:\Users\salon\Desktop\Application Alon\ConsoleApplication1\ConsoleApplicati
on1\bin\Debug\chromedriver.log
[156:4144:0828/233852:ERROR:platform_thread_win.cc(127)] NOT IMPLEMENTED
[5804:5712:0828/233856:ERROR:textfield.h(173)] NOT IMPLEMENTED
I have windows 7 if it's needed..
any help appreciated!
For the later versions of Chrome (27+), there is a new shiny ChromeDriver:
http://code.google.com/p/chromedriver/downloads/list
Note the section within the summary on the page...
ChromeDriver server for win32 (v2.2.215849.dyu) supports Chrome v27-30
Also, you should remove the Thoughtworks & WebDriverBackedSelenium references, they are not required and you don't seem to be using them.