I have the issue that sometimes our application don't start and therefore a connect of the Selenium will fail. It is OK for me that I get the error and the test fails.
My issue is in these case: That the following commands still starts the chromedriver.exe but I don't get a driver object back. So I can't stop the driver afterwards.
_driver = new Driver()
.SetChromeOptionsWeb()
.SetDriver()
.StartDriver();
Is there any possibility to not end up with a chromedriver.exe deamon process at the machine?
Thanks in advance
Nico
You need to surround it into try/catch/finally block or just make use of using.
For example you could use this piece of code:
using var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://example.com");
//
// some driver actions
//
// Here the purpose of this task is to keep the driver up.
await CustomTaskAsync();
// And here after last action the driver will be disposed
Related
I have some RPA processes which use ChromeDriver to connect to specific instances of Chrome identified by its remote-debugging-port and a custom command arument for chrome which idenitifies the specific chrome instances as "from my program".
I have a program using Selenium ChromeDriver. I do not let ChromeDriver create the Chrome Instance, but rahter re-use an existing one. So when my program starts up it can find the specific Chrome I want to use, and connect a new ChromeDriver to it. The issue is that sometimes the ChromeDriver is left running stuck because I exited without Quitting it (this is development work - stuff happens!)
I would like to be able to somehow tag the ChromeDriver that was launched by my programs. Iti is easy to tage the Chrome instance - I just pass in any unique argument and it happily accepts it, as in "--originator=me", then I can go through the chrome processes, get their command line and know which Chrome is mine. But I do not know how to do this with ChromeDriver. Here are ideas I have that have not worked:
Pass in a command line argument to chromedriver, but the only argument I see in the process is "port=12345"
Get the Process ID of the chromedriver I just created. But I do not know how to ask the new driver for this, even though I have access to it.
Any ideas on how to identify a chromedriver that my process created, assuming that later on my program will be looking for this specific instance?
You can use a ChromeDriverService to create a ChromeDriver then give the service a LogPath. That LogPathcan be the identifier as long as it's a valid file name. Just like this:
var svc = ChromeDriverService.CreateDefaultService();
svc.LogPath = LogPath
ChromeOptions options = new ChromeOptions();
driver = new ChromeDriver(svc, options);
Then if you want to find the specific ChromeDriver, just find the windows process with this command-line argument. In this case we really don't care about the contents of that file itself, just the fact that the magic word is now programmatically discoverable.
I've been battling the commonly seen "HTTP request to the remote WebDriver server for URL ... timed out after x seconds" for several months in an attempt to run tests against two browsers simultaneously (Chrome and IE), spending hours at a time trawling through stackoverflow and search engine results to attempt to find a solution.
My behavior, like others before me, varies between timing out at a click function or when attempting to get a url, and I have increased pageload and implicit wait timeouts to over 600 seconds in various cases, inserting the waits before an element, after a url is called, before a url is called, after the driver constructor is called and as a parameter in the driver object call.
I have attempted to include javascript exectutor scripts (provided from answers in previous SO posts on this issue) that check for the page load ready state to be complete before continuing with an action, to no success.
I have attempted to update my chrome and IE, selenium web and support drivers all to the latest compatible versions, manually calling the binary for the latest compatible browser executable - as well as attempting to roll back to previous versions where people have reported success (chrome v48, chromedriver 2.22.0.0, webdriver 2.53.1). I've tried adding "no-sandbox" as a chrome option, ensured that my IE security zones all shared the same level of protection.
I've investigated whether my page is using AJAX scripts and attempted to use the solutions provided in various threads to accommodate for any dynamic content.
When running either IE or Chrome individually, outside of the parallel query, no timeout issues are observed. The issue specifically occurs when chrome initializes its remote WebDriver instance. I've also tried using 32bit and 64bit versions of the chrome/ie drivers.
I've pulled information out of many topics, and pages, but these are some of the most relevant ones.
Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds
https://sqa.stackexchange.com/questions/13326/the-http-request-to-the-remote-webdriver-server-timed-out-after-60-seconds
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5441
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5071
Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds
Selenium WebDriver throws Timeout exceptions sporadically
Here's an example of the output:
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.AggregateException : One or more errors occurred.
----> OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:52240/session/a969dbe2-3b0c-461f-a979-21bafec0dd8e/element/7005aeab-ff31-454a-8f78-0a39ad861695/click timed out after 120 seconds.
----> System.Net.WebException : The request was aborted: The operation has timed out.
I call the drivers from a case list where there are later added in to the parallel query:
private static IWebDriver DefineDriver(Browser supportedbrowsers)
{
var baseDriverPath = ConfigurationManager.AppSettings["BaseDriverPath"].ToString();
var ieDriverFolder = ConfigurationManager.AppSettings["IeDriverFolder"].ToString();
var chromeDriverFolder = ConfigurationManager.AppSettings["ChromeDriverFolder"].ToString();
ChromeOptions chromeoptions = new ChromeOptions();
chromeoptions.BinaryLocation = #"C:\WebDrivers\Binary\chrome32_49.0.2623.75\chrome.exe";
chromeoptions.AddArgument("no-sandbox");
InternetExplorerOptions ieoptions = new InternetExplorerOptions();
ieoptions.IntroduceInstabilityByIgnoringProtectedModeSettings = false;
IWebDriver driver = null;
switch (supportedbrowsers)
{
case Browser.Chrome:
driver = new ChromeDriver(Path.Combine(baseDriverPath, chromeDriverFolder), chromeoptions, TimeSpan.FromMinutes(5));
break;
case Browser.InternetExplorer:
driver = new InternetExplorerDriver(Path.Combine(baseDriverPath, ieDriverFolder), ieoptions, TimeSpan.FromMinutes(5));
break;
default:
driver = new ChromeDriver(Path.Combine(baseDriverPath, chromeDriverFolder), chromeoptions, TimeSpan.FromMinutes(5));
break;
}
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(120));
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMinutes(10));
driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMinutes(10));
driver.Manage().Window.Maximize();
return driver;
}
In my test code, I am simply launching a page, navigating to another local page and then attempting to click a button that is immediately visible on the page.
I've tried wrapping the click command for the button in a try catch, added explicit waits with expected conditions (displayed, enabled, isclickable), used thread sleep which have all worked as expected when running a single browser.
For example, I call the button via:
public void SelectAddWorkWorkPageButton()
{
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementToBeClickable(addNewWorkItemWorkPageBtn));
addNewWorkItemWorkPageBtn.Click();
}
Which locates the following element:
//Create New Button
[FindsBy(How = How.Id, Using = "btnWorkDefinitionCreateNewWorkDefinition")]
public IWebElement addNewWorkItemWorkPageBtn { get; set; }
And it's HTML:
<i id="btnWorkDefinitionCreateNewWorkDefinition" title="Add work" class="fa fa-plus-circle cursorPointer crudIcon" style="font-size: 20px;margin:0;padding-left:15px" ng-click="AddNewWorkDefinition()" role="button" tabindex="0"></i>
As a separate note regarding the timeouts, when updating to the latest versions of the WebDriver, I have also updated the timeouts to their new format:
//driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(120);
//driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
//driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(120);
This issue seems to have existed in the community since as far back as 2012 and has, to my finding, never been isolated and clearly identified, with people still reporting it in May this year.
Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds
After attempting several more workarounds, including the use of Protractor to account for AngularJS code, I've finally isolated the cause of the "The HTTP request to the remote WebDriver server for URL" exception message down to a specific issue when running the IEDriver individually or in parallel against the application in test.
It appears that the application was using a SignalR connection to handle certain processes and this causing the IEDriver actions (such as a click event) to timeout because the SignalR connection would never complete and therefore result in the IEDriver not being able to determine that the page had finished loading before it could perform another action.
When the SignalR connection type was updated to use "Long Polling" this resolved the IEDriver timeout issue entirely.
Better explanations are available in these posts, and much credit is owed to those who contributed within, I'd never have guessed that SignalR was the cause otherwise:
https://github.com/SignalR/SignalR/issues/293
SignalR w/ Web Sockets
C# Protractor AngularJS IEDriverServer Click() Exception "Timed out waiting for page to load"
Thanks.
I'm trying to create an automation test script using Protractor.net for an AngularJS platform, with Selenium in C#. I've created the driver using the below code.
driver = new FirefoxDriver();
Ngdriver = new NgWebDriver(driver);
And then attempted to locate and element as follows:
Ngdriver.FindElement(NgBy.Model("vm.reference")).SendKeys("Test");
However, I'm receiving an exception: Timed out waiting for async script result after 45ms.
Thanks in advance
I resolved this by using the SetScriptTimeout.
ngDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
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.
I want to use Selenium Web Driver in VS 2010 C# to open a Chrome browser, navigate to some web page and then close the driver but keep the browser open. I realize that I will have to manually close the browser afterwards and I'm okay with that.
So far I have:
DriverService service = ChromeDriverService.CreateDefaultService();
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("chrome.detach",true);
m_driver = new ChromeDriver(service, options, TimeSpan.FromMilliseconds(1000));
[m_driver does stuff like navigate page, double click stuff, etc]
[last line: try to close driver but not browser]
I have tried all the following as the last line
m_driver.Dispose(); // closes both browser and driver
m_driver.Close(); //closes just the browser and not the driver
m_driver.Quit(); // closes both browser and driver
service.Dispose(); // closes both browser and driver
Any ideas?
We can detach chrome instance from chromedriver using "detach" options.
Sample Code:
ChromeDriverService cdservice = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("/path/to/chromedriver.exe"))
.withLogFile(new File("/path/to/chromedriver.log"))
.usingAnyFreePort().withVerbose(true).build();
cdservice.start();
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("detach", true);
ChromeDriver driver = new ChromeDriver(cdservice,options);
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
driver.get("http://www.google.com/");
// Do not call driver.quit().. instead stop chromedriver service.
cdservice.stop();
This is simply not possible, that kind of separation does not exist.
chromeservice.driver.close()
has worked for me in the past but in this case you may need to write some coding for a method.
It is posible a least in c# you need the next lines:
driverOptions.AddExcludedArgument("enable-automation");
driverOptions.AddAdditionalCapability("useAutomationExtension", false);
(Python) When I called the selenium .get() function, Chrome would open up and close shortly after. I found online the advice to use the following code to remedy this issue: It worked for me in Python3; MacOSX 12.3 Monterey; Chrome Version 105.0.5195.102
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(chrome_options=options, executable_path='/Users/<user_acct_name>/.wdm/drivers/chromedriver/mac64/105.0.5195/chromedriver')