selenium chrome driver stops working after publish application - c#

I have this code. And I put chromedriver.exe in my solution folder bin>>debug
ChromeOptions options = new ChromeOptions();
options.AddArgument("--disable-notifications");
IWebDriver driver = new ChromeDriver(options);
driver.Manage().Window.Maximize();
driver.Url = url;
It works ok when I debug application but after publishing it throws an exception
what can I do? It's simple console application

You should try newer ChromeDriver and Selenium versions. I have just checked this code on Selenium.WebDriver 3.4.0 and Selenium.WebDriver.ChromeDriver 2.30.0.1
Starting ChromeDriver 2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41) on port 2935
Only local connections are allowed.
Press any key to continue . . .
It works fine for debug and release versions.

Related

Run selenium on an already existing chrome browser?

Is it possible to open my own (normal) chrome browser and have selenium run on this browser?
I saw some existing topics about this wrt. Python: Running Selenium on an existing Chrome Browser Window, how is someone doing this through C# and Selenium?
Type : chrome://version/ in browser you will get executable path of chrome.exe
copy this and close all chrome instance.
**close all chrome instance and **
start chrome as:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=5555
verify chrome is started with port open by going to localhost:5555
Now add remote debugging port as:
var options = new ChromeOptions();
options.debuggerAddress= "127.0.0.1:5555";
var driver = new ChromeDriver(options);

C# Selenium Chromedriver only shows 'data'

I created a very simple C# project to test Selenium and Chrome Driver, but when I run it, it gets stuck at the very first line, ie. creating ChromeDriver object.
I have set up as following:
.NET Core 3.1 console app (also tried .NET 4.7)
Installed Selenium.WebDriver 3.141.0 and Selenium.WebDriver.ChromeDriver 87.0.4280.8800.
My Chrome version is "Version 87.0.4280.88 (Official Build) (64-bit)". I have double-checked compatibility with Chrome and ChromeDriver.
Code:
using OpenQA.Selenium.Chrome;
namespace MyFirstSelenium
{
class Program
{
static void Main(string[] args)
{
ChromeDriver chrome = new ChromeDriver();
chrome.Navigate().GoToUrl("https://www.google.co.jp/");
}
}
}
visual studio screen
chromedriver.exe is copied to the debug folder as expected, so I assume the problem is neither compatibility nor path.
chromedriver
When I run the code, the result is an empty window with 'data' in the address bar. No error is thrown. I have searched for several hours and found some articles, but most of them are old and none of these answers led to success.
Any help is appreciated. Thank you.
Added chromedriver.exe verbose console output.
#Piotr M.
chromedriver console
logfile
https://drive.google.com/file/d/1ECOS8E55aaTFV63e8P-7n6uRVcf49PRN/view?usp=sharing
New code
Works when I first execute "chromedriver.exe --verbose --log-path=chromedriver.log", but without it, it throws WebDriverException.
OpenQA.Selenium.WebDriverException: 'A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL localhost:9515/session. The status of the exception was UnknownError, and the message was: No connection could be made because the target machine actively refused it. No connection could be made because the target machine actively refused it.'
var chromeOptions = new ChromeOptions();
chromeOptions.BrowserVersion = "87";
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:9515"), chromeOptions);
Possibly a classic case of cyclic redundancy.
chrome is a reserved word, you may have to change the variable name to something else e.g. chromex. So your effective line of code will be:
ChromeDriver chromex = new ChromeDriver();
Additional Consideration
Consider the following aspects aswell:
Instead of using the ChromeDriver class use the IWebDriver interface.
IWebDriver driver = new ChromeDriver();
Instead of the partial url google.co.jp/ you need to pass the complete url through GoToUrl() as follows:
driver.Navigate().GoToUrl(#"https://www.google.co.jp/");

Chrome extension not being added to Chrome browser when using ChromeDriver for Selenium

I am attempting to open Chrome browser with an extension. Chrome opens, but it doesn't have my extension. Here is my code. Please let me know what I am doing wrong.
private IWebDriver GetChromeDriver(BrowserConfigurationOptions browserConfigOptions)
{
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var chromeDriverPath = Path.GetFullPath(outPutDirectory + #"\Drivers");
var options = new ChromeOptions();
options.AddExtension(outPutDirectory + #"\3.1.5_0.crx");
options.AddArguments("disable-infobars");
options.AddUserProfilePreference("credentials_enable_service", false);
if (browserConfigOptions.KioskModeForChrome)
options.AddArgument("--kiosk");
return new ChromeDriver(chromeDriverPath, options);
}
The extension exists in the path where I expect it to be.
Chrome version: 60
ChromeDriver v:2.29
Selenium v: 3.5.2
The issue is that WebDriver 3.5.2 does not support ChromeDriver 2.29. These problems can be resolved if we downgrade to WebDriver 3.4. Then everything works. I logged an issue on their Github but I believe that backwards compatibility is not expected between WebDriver and older versions of ChromeDriver.

The path to the driver executable must be set by the webdriver.chrome.driver system property - Selenium Error

I have an infuriating Selenium error:
The path to the driver executable must be set by the webdriver.chrome.driver system property
Here is the code I am using:
Environment.SetEnvironmentVariable("webdriver.chrome.driver", #"C:\ChromeDriver\chromedriver.exe");
DesiredCapabilities capability = DesiredCapabilities.Chrome();
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
capability.SetCapability(ChromeOptions.Capability, options);
Uri url = new Uri("http://localhost:5050/wd/hub");
//error on this line
IWebDriver driver = new RemoteWebDriver(url, capability);
I have the driver on disk, at the location.
The selenium server is running, as shown below:
Server
I have added the selenium binary as a system variable, as shown below:
Variables
I have restarted the server too.
What am I missing? It feels as though I am doing everything correctly, but it's not working.
Thanks
With the new selenium, which is 3.0 you should use:
java -Dwebdriver.chrome.driver=path_to_chrome_driver -jar selenium-server-standalone-3.0.0-beta2.jar
If you are using selenium version below 3.0 you need to reverse the order of selenium with the driver, like:
java -Dwebdriver.chrome.driver=path_to_chrome_driver -jar selenium_server.jar
Also make sure selenium server is compatible with chromedriver.
Other thing to check is that chrome browser is up to date.

Failed to start up socket within 45000

I'm using FF version 19
it was all working fine till yesterday and suddenly today morning i start getting this error and i have the same exact code that was running before, no change nothing
error message:
Test 'M:.TestCases.12' failed: Failed to start up socket within 45000
OpenQA.Selenium.WebDriverException: Failed to start up socket within 45000
at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.ConnectToBrowser(Int64 timeToWaitInMilliSeconds)
at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start()
at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient()
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile, TimeSpan commandTimeout)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxProfile profile)
0 passed, 1 failed, 0 skipped, took 145.80 seconds (Ad hoc).
here is my source code:
public static IWebDriver GetDriver()
{
switch (Common.BrowserSelected)
{
case "ff":
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", url);
drv = new FirefoxDriver(profile);
break;
case "ie":
var options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
drv = new InternetExplorerDriver(options);
break;
case "chrome":
//_driver = new ChromeDriver();
break;
}
return drv;
}
Firefox 19 'support' was added in Selenium's latest versions. So since you are using .NET, the direct download for the latest at the time of this post is version 2.31.2:
selenium-release.storage.googleapis.com/index.html
I have this issue with Firefox 43 and Selenium 2.48.
It happens when your Selenium driver server is running in a 32 bit process and you start the 64 bit version of Firefox.
The cause is that the webdriver server tries to connect to port 7055 which should be opened by the webdriver that runs in the Firefox executable. But you can see in TcpView from www.sysinternals.com that Firefox does not open this port. So the driver waits until his timeout (45 seconds) elapses.
This happens even after turning off the Windows Firewall completely.
All posts that I found in internet do NOT help: Upgrade Selenium, downgrade Firefox, etc..
But after installing the 32 bit version of the same Firefox 43 it works. I see in TcpView how Firefox 32 bit opens the port correctly:
In my code I use
FirefoxProfile Prof = new FirefoxProfile();
FirefoxBinary Bin = new FirefoxBinary(sBrowserExe);
mDriver = new FirefoxDriver(Bin, Prof);
With sBrowserExe = "C:\Program Files\Mozilla Firefox 43\firefox.exe"
the 64 bit version of Firefox 43 is started and I get the timeout exception.
With sBrowserExe = "C:\Program Files (x86)\Mozilla Firefox 43\firefox.exe"
the 32 bit version of Firefox 43 is started and it works!
UPDATE: The developers from Firefox now broke Selenium support COMPLETELY. New Firefox versions from 48 upwards need a digital signature for all extensions to be installed.
https://wiki.mozilla.org/Addons/Extension_Signing
What I don't understand is why Selenium people cannot get a signature for the current Selenium driver??
Firefox version 47.0 has a bug that does not allow to use it with Selenium. This bug has been fixed in version 47.0.1.
Firefox versions from 48.0 and above do not install the old Selenium driver anymore. They must be automated with Marionette (= Gecko) driver.
The problem is that Marionette is still beta and has a lot of missing features so there is currently no solution to automate the new Firefox versions.
As you see here the new driver is full of bugs: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver/status
If Upgrading Webdriver doesn't help you can downgrade FireFox that will solve issue.
Which version of Selenium IDE you are using? Try downgrading the Firefox version. The release notes of selenium IDE is mentioned in below link.
https://code.google.com/p/selenium/wiki/SeIDEReleaseNotes
Hope this helps.
Install all the updates in your Nuget package manager. Restart IDE.
Downgrading firefox version is not recommended for testing. But last but one version downgrade sounds good.
This solution worked for me.

Categories

Resources