I am trying to automate testing of an electron application (from third party vendor) using Selenium and C# and am getting the error: OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:. Attached is the piece of code.
ChromeOptions options = new ChromeOptions();
ChromeDriverService chromeService = ChromeDriverService.CreateDefaultService(#"C:\Selenium\chromedriver_win32_1",
#"<path to exe of electron application>");
options.AddArgument("–no-sandbox");
options.AddArgument("–disable-dev-shm-usage");
driver = new ChromeDriver(chromeService, options, TimeSpan.FromSeconds(180));
Actual result:
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:
Expected Result: driver instance is created successfully
NOTE: The electron application is launched successfully. Also when I remove the path to exe of electron application there is no error and driver instance is created successfully
There can be different problems but when I am testing electron apps, I prefer to use following kind of options to set binary.
Maybe following kind of code block can solve your issue.
ChromeOptions options = new ChromeOptions();
options.setBinary(binaryPath);
options.addArguments("--app=" + argPath);
options.AddArgument("–no-sandbox");
options.AddArgument("–disable-dev-shm-usage");
options.setCapability("chromeOptions", options);
driver = new ChromeDriver(options);
Related
I am trying to launch my electron app where it should accept my 'path to the index.js' and '--start server' as the arguments to load the html content of electron. But my chrome options not considering the arguments passed and it just opens the default electron.exe.
enter image description here
Below is the code I tried to launch app:
ChromeOptions electronOption = new ChromeOptions();
electronOption.AddArguments("C:\Program Files\src\index.js", "--startServer");
var service = ChromeDriverService.CreateDefaultService("path to chromedriver.exe", "path to electron.exe");
driver = new ChromeDriver(service, electronOption);
I'm trying to create a ChromeDriver object using the ChromeOptions that will print the screen to a p.pdf. If I run the following command I'll get that:
"C:\Program Files (x86)\Google\Chrome\Application\chrome" --headless --enable-logging --disable-gpu --print-to-pdf=C:\Users\Me\Documents\google.pdf
Now If I try using that "print-to-pdf" argument with Selenium ChromeDriver, it times out:
var fileloc = #"C:\Users\me\myFolder\doc.pdf";
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments(new List<string>() {
"headless",
"disable-gpu",
$"print-to-pdf={fileloc} https://www.stackoverflow.com/"
});
var browser = new ChromeDriver(chromeOptions);
Here is the exception error:
The HTTP request to the remote WebDriver server for URL http://localhost:55936/session timed out after 60 seconds.
The console says this:
Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 55936. Only local connections are allowed.
If I were to run it removing only the PDF argument, it seems to run just fine. Any thoughts on how to fix?
I am running chromedriver on windows server 2016 with IIS, i have my test project installed and invoking it with an MVC5 API. That all seems fine but chromedriver and chrome.exe only seems to open as a background processes.
The same code opens these fine locally, i am not using any of the driver flags for headless browsing either. if i return the drive page source i can see that chromedriver went to google and returned the correct html in my API.
It just does not work for normal / non headless tests with google or our application.
var driver = x.StartWebDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://www.google.com");
return driver.PageSource;
Any ideas?
I have got the same issue and this is how I solve this:
Open a command prompt and navigate to your ChromeDriver location.
Execute chromedriver.exe and you will see the message as below.
image here
In the image above you see chrome driver is listening on port 9515.
Now change your code as below, rebuild and call you api to execute your test.
ChromeOptions options = new ChromeOptions();
//set your chromeoptions here
Uri uri = new Uri("http://localhost:**9515");
_driver = new RemoteWebDriver(uri, options);
Open the chrome driver and note the port number(eg:5353)
In java:
System.setProperty(chromeDriverName, chromeDriverLocation);
ChromeOptions options = new ChromeOptions();
URL uri = new URL(chromeDriverPort);//http://localhost:5353
WebDriver driver = new RemoteWebDriver(uri, options);
your problem gets solved in is server.
How do I correctly set up a proxy with Selenium C# PhantomJSDriver in a C# console application?
I have looked high/low at all online docs and similar post with no success:
Add proxy to PhantomJSDriver (Selenium C#)
Using a proxy with Selenium
How to Setup Private Proxy with Selenium?
Here's my code:
var options = new PhantomJSOptions();
options.AddAdditionalCapability(CapabilityType.Proxy,"123.456.748.99:80");
IWebDriver driver = new PhantomJSDriver(options);
Running this code I get the following error(s):
**ERROR: Unexpected error. TypeError - undefined is not an object (evaluating 'proxyCapability["proxyType"].toLowerCase')
PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.AddArgument(string.Format("--proxy-auth={0}:{1}", proxyUsername, proxyPassword));
service.AddArgument(string.Format("--proxy={0}:{1}", proxyAddress, proxyPort));
IWebDriver driver = new PhantomJSDriver(service);
in service you have more options to add if you need.
When I create a new chrome driver in Selenium while Google Chrome is already running AND I am referencing the users settings/data (via user-data-dir). A new Chrome window will open, but my application will hang. The ChromeDriver console will display the following error each second: DevTools Request: 127.0.0.1:12585/json/version. DevTools request failed
Screenshot:
Code to instantiate the driver:
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
//driverService.HideCommandPromptWindow = true;
driverService.EnableVerboseLogging = true;
string path = Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%\\Google\\Chrome\\User Data");
ChromeOptions options = new ChromeOptions();
options.AddArguments("user-data-dir=" + path);
options.AddArguments("--start-maximized");
options.AddArguments("--disable-extensions");
IWebDriver driver = new ChromeDriver(driverService, options);
This will work perfectly fine in every instance if I do not try and load user settings/data. If I am trying to load user setting/data it will only work if there is no instance of Chrome running on the device already.
Versions:
Selenium v 2.47.0
ChromeDriver v 2.16.333243
Chrome v44.0.2403
What can I do to resolve this?
If anyone was looking for answer like me;
https://bugs.chromium.org/p/chromedriver/issues/detail?id=2443
This behavior is by design. Two instances of Chrome can't use the same user-data-dir at the same time. Otherwise they would try to update the same set of files and cause corruptions. So if an instance is already running, attempting to start another instance using the same user-data-dir will cause the second instance to ask the first instance to open a new window, and then the second instance exits.