I am using C#, Microsoft.VisualStudio.TestTools.UnitTesting and Selenium to test a website.
I know MS Edge is no longer being developed, and is being replaced with a Chromium-based product. In the interim, I would still like to be able to tell my customers that Edge is a supported browser until the replacement occurs.
But it looks like using the selenium EdgeDriver requires a valid microsoftwebdriver - and the latest one is not compatible with the latest version of Windows - my machine uses Windows 10 Version 1809 / build 17763.379.
Has anyone been able to get Edge testing to work with Selenium on a Windows 10 build 1809 machine? If so, please show some sample code and needed steps / references / usings / etc.
If seen a few posting about this where some responses say it is impossible, and others say it is possible - but the ones that say it is possible don't show any actual code or reference names.
I apologize to any readers that I didn't post the solution I eventually found - which is quite simple. Here's the code of instantiating the driver:
var service = OpenQA.Selenium.Edge.EdgeDriverService.CreateDefaultService(#"C:\Drivers", #"msedgedriver.exe");
service.UseVerboseLogging = true;
service.UseSpecCompliantProtocol = true;
service.Start();
var options = new OpenQA.Selenium.Edge.EdgeOptions();
// For future reference - please check to see if there are options that should be set...
driver = new RemoteWebDriver(service.ServiceUrl, options);
As you can see, I keep the latest edge driver in a dircetory called "C:\Drivers". The latest driver can always be downloaded from the selenium website downloads page (https://www.selenium.dev/downloads/) - expand the Browsers section on that page.
Sample C# Code
else if (AppSettings.Browser == "Edge")
{
EdgeOptions edgeOptions = new EdgeOptions()
{
UseInPrivateBrowsing = true,
};
driver = new EdgeDriver(edgeOptions);
}
and Remove all Nuget references to MicrosoftDriver, Clean the Solution
Then Run the below command in CMD Admin mode
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Note: This Solution is for Microsoft Edge version 18 or Above
Well after a long time navigating the internet found a solution for that!
At least you have to remove your NuGet package WebDriver(actual version) and install the beta version, then go to this website https://www.nuget.org/packages/Selenium.WebDriver/4.0.0-beta2 copy the beta nuget you want in my case 4.0.0 till the moment, then open your visual studio (mine is 2019) Tools>Nuget Package Manager>Package Manger Console here you paste your copy.
Ps. make download from edge chromium
using OpenQA.Selenium.Edge;
public class Example Edger
{
private IWebDriver driver;
public void SetupTest()
{
driver = new EdgeDriver();
driver.Manage().Window.Maximize();
}
}
You need to install edge driver version equal to the version of edge in your system. To find edge version number go to settings->about microsoft edge .Download the correct version from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver After downloading you need to change the name of driver to MicrosoftWebDriver.exe from msedgedriver.exe. Then It will work :)
Related
For compatibility reasons I prefer to use Chrome version 55.0.2883.75 with Chromedriver v. 2.26. I downloaded the older version of chrome from https://www.slimjet.com/chrome/google-chrome-old-version.php and Chromedriver 2.26 from https://chromedriver.storage.googleapis.com/index.html?path=2.26/.
I am using the following code to attempt to set my Chrome binary location:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome('chromedriver.exe', chrome_options = options)
However, when I attempt to launch the WebDriver Python returns the following error:
WebDriverException: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.26.436362
(5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.14393 x86_64)
I have tried searching through similar questions and answers but have not had any luck so far. Any help is greatly appreciated - thank you in advance!
This error message...
WebDriverException: unknown error: cannot find Chrome binary
...implies that the ChromeDriver was unable to find the Chrome binary in the default location for your system.
As per the ChromeDriver - Requirements:
The server expects you to have Chrome installed in the default location for each system:
OS
Expected Location of Chrome
Linux
/usr/bin/google-chrome1
Mac
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP
%HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista and newer
C:\Users%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Using a Chrome executable in a non-standard location
However you can also override the default Chrome binary location as follows:
To use Chrome version 55.x installed in non standard location through ChromeDriver v2.26 you can use the following code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()
Related Docs
Reference
You can find a detailed discussion in:
Is Chrome installation needed or only chromedriver when using Selenium?
What happened to me is that I didn't have chrome, the main browser, installed.
Download the browser and it fixes this issue.
Using an old version of chrome driver with the latest Google Chrome locally gave me the same exception.
Just go to the ChromeDriver page and make sure you have the latest version.
I faced similar issue in MacOS. Even after setting binary path in chromeoptions, it didn't work. It got fixed after installing npm i chromedriver
It is also important to download Chrome from the actual website. I ran into the same problem, but I had downloaded Chrome from the Ubuntu software package manager. I uninstalled the package manager version and installed from the website, and the error resolved. Same issue could probably arise installing from other package managers.
Check https://sites.google.com/a/chromium.org/chromedriver/getting-started
You can specify the binary path in the constructor of the webdriver:
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
I did this to solve my problem
private WebDriver driver;
#Before
public void StartBrowser() {
System.setProperty("webdriver.chrome.driver", "C://opt//WebDriver//bin//chromedriver.exe");
driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");}
I have solved this problem by installing Google Chrome link and it solved problem automatically (I use Kali Linux) and be sure that it is installed to the "/usr/bin"(default it is downloaded to here).
when i go to command prompt and type chromedriver -v:
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945#{#614})
but when i try to run this code :
from selenium import webdriver
class InstaBot:
def __init__(self):
self.driver=webdriver.Chrome()
self.driver.get("www.instagram.com")
InstaBot()
it gives me error like this:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80
why this is happening i tried to remove selenium as well as chromedriver
and reinstall of version 79.0.3945 but when i run it ,it show this can only be run on version 80
my chrome version is 79.0.3945 which is lastest ,and version 80 chrome is chrome beta
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80
...implies that the ChromeDriver v80.0 was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You mentioned about using chromedriver=79.0.3945.36 and the release notes of chromedriver=79.0 clearly mentions the following :
Supports Chrome v79
Presumably you are using chrome v79.0 browser.
So, it's quite evident your have chromedriver=80.0 present within your system which is also within the system PATH variable and is invoked while you:
self.driver=webdriver.Chrome()
Solution
There are two solutions:
Either you upgrade chrome to Chrome Version 80.0 level. (as per ChromeDriver v80.0 release notes)
Or you can override the default chromedriver v80.0 binary location with chromedriver v79.0 binary location as follows:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
You can find a detailed discussion in Ubuntu: selenium.common.exceptions: session not created: This version of ChromeDriver only supports Chrome version 79
Additional Considerations
Ensure to:
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Reference
You can find a relevant detailed discussion in:
How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium
Use Bonigarcia plugin in project. After that it will manage all driver by itself.It reads chrome version and instantiate driver accordingly.
for help follow my post :
https://www.linkedin.com/pulse/webdrivermanager-bonigarcia-rohan-ravi-yadav/
or original git link/post
https://github.com/bonigarcia/webdrivermanager
If any help required , Let me know
I am using selenium remotedriver(with C#) for chrome and edge. The tests seem to run fine on the chrome browser but not on edge. Edge is launched but fails to navigate to the specified uri.
I tried to make sure, I have the same version of webdriver as the installed version of edge, I am on windows 10 so it is already turned on.
var options = new EdgeOptions();
options.PageLoadStrategy = PageLoadStrategy.Eager;
_driver = new EdgeDriver(driverPath,options);
_driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
_driver.Navigate().GoToUrl("www.google.com");
The image contains the nuget packages added to the project
Microsoft Edge 44.18362.329.0 that is installed. Any help would be deeply appreciated.
I tried to test the issue on my side with Microsoft Edge 44.18362.1.0, Windows 10, Selenium web driver version V3.141.0
Tested code:
class Program
{
private static StringBuilder verificationErrors;
[Obsolete]
static void Main(string[] args)
{
var options = new EdgeOptions();
options.PageLoadStrategy = PageLoadStrategy.Eager;
IWebDriver driver = new EdgeDriver(options);
driver.Navigate().GoToUrl("www.google.com");
}
}
Code is working fine on my side and opening the web page without any issue.
Output:
I can see various entries for Web drivers in your package manager.
I suggest you to just installed the Selenium web driver v3.141.0 in new separate project and try to run this code in it to check whether it helps solve the issue or not.
If it solves the issue than remove unnecessary entries from your project may help to solve your issue.
Seen a lot of questions regarding Selenium 2.53.1 and Firefox 47.0.1, but none in regards to the Selenium 3 Beta release. I am attempting to use the new gecko/marionette Firefox webdrivers, but even though I have the driver location in; my environment path, Firefox install folder in programs, and give the drive location in the system environment, it will still not work correctly.
Error:
The geckodriver.exe does not exist in the current directory or in a directory on the PATH environment variable. The driver can be downloaded at https://github.com/mozilla/geckodriver/releases.
Using:
Selenium 2.53.1 server
Firefox 48
Selenium 3 Beta DLLs
Window 10
Example Code 1
using OpenQA.Selenium.Firefox;
public static class FirefoxInitialise
{
public static IWebDriver Driver {get; set;}
Driver = new FirefoxDriver();
}
Also attempted the below:
using OpenQA.Selenium.Firefox;
public static class FirefoxInitialise
{
public static IWebDriver Driver {get; set;}
FirefoxDriverServices service = FirefoxDriverService.CreateDefaultService();
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe";
FirefoxOptions options = new FirefoxOptions();
TimeSpan time = TimeSpan.FromSeconds(10);
Driver = new FirefoxDriver(service, options, time);
}
Any help or insight as to why the code still won't detect this driver would be greatly appreciated it.
Try to put the geckodriver.exe in your path: C:\Users\YourName\Documents\Visual Studio 2013\Projects\seleniump\seleniump\bin\Debug
you can find geckodriver.exe at this link:
https://github.com/mozilla/geckodriver/releases
Install the Selenium.Firefox.Webdriver NuGet package.
This will copy geckodriver.exe to the bin folder.
This solution may helps you fix problem: ( It did help me though)
public class TestResult {
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[TestInitialize]
public void SetupTest() {
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\geckodriver", "geckodriver.exe");
service.Port = 64444;
service.FirefoxBinaryPath = #"C:\Program Files (x86)\Firefox Developer Edition\firefox.exe";
driver = new FirefoxDriver(service);
baseURL = "http://localhost:49539";
verificationErrors = new StringBuilder();
}
}
REFERENCE
Check out #juver-malpartida 's Answer
If u include the geckodriver.exe in your project and you copy it to your target directory when you compile, the webdriver works as it did in previous versions.
This is for who is the begginers ill write the short version in the below after this post :)
The easiest way first you need to download all drivers what browser you use and extract all drivers into e.g. C:\Selenium\ there and go to VisualStudio and from here add Selenium packages shown in the pictures Click here in console write this code PM>Install-Package Selenium.WebDriver after that copy your drivers directory and from windows search tab type variables and select (Edit the system environment and variables) shown pic2 in this windows you will have advanced tab at the below click Environment Variables... here you have System variables section find PATH or Path Variable and edit it be careful don't delete it!! next click new - paste directory of drivers and click all windws ok button that's all. restart your VS programm and ckeck it. After this you don't have to add director path into your Constructor like
IWebDriver driver2 = new InternetExplorerDriver(#"C:\Selenium");
One more thing don't forget to import files.
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
For more Advanced IT guys.
Add into Environment Path Yours drivers directory.
VisualStudio install Selenium using NuGet package manager in console mode or how would u like.
PM> Install-Package Selenium.WebDriver
restart VS.
In your project, click on Tools --> Nuget Package Manager --> Manage NuGet Packages for Solution...
The in the open Window
Browse
Selenium.FireFox.WebDriver
Select Project and your project Name and click on install.
This is the easer form to put the driver on your Selenium Project.
I would try this:
First, make sure your C# project runs the same .NET framework version as the Client Driver's libraries (when you download them from Selenium HQ, you should see the framework version they're based on). I have 3.5 and 4.0 as of 9/15/2017, so I had to downgrade my C# project to .NET 4.0 to use the 4.0 Client Driver libraries.
In your code, when creating the Firefox Driver Service, make sure you explicitly specify the path to where your geckodriver.exe is located. See how I've added a path parameter to your call to FirefoxDriverService.CreateDefaultService:
using OpenQA.Selenium.Firefox;
public static class FirefoxInitialise
{
private static IWebDriver Driver{get; set;}
public static IWebDriver Init()
{
// I'm assuming your geckodriver.exe is located there:
// #"C:\MyGeckoDriverExePath\geckodriver.exe"
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(#"C:\MyGeckoDriverExePath\");
service.FirefoxBinaryPath = #"C:\Program Files\Mozilla Firefox\firefox.exe"; // May not be necessary
FirefoxOptions options = new FirefoxOptions();
TimeSpan time = TimeSpan.FromSeconds(10);
Driver = new FirefoxDriver(service, options, time);
return Driver;
}
}
So you can use :
IWebDriver driver = FirefoxInitialise.Init();
If you have the executable in path environment variable, it likely means that it doesn't have permission to access it. As a workaround, try to run Visual Studio as administrator.
Or you could move it to somewhere that it have permission. Eg:
var service = FirefoxDriverService.CreateDefaultService(#"D:\tmp\Binaries");
service.FirefoxBinaryPath = FirefoxBinary;
var options = new FirefoxOptions();
options.SetPreference("browser.private.browsing.autostart", true);
_driver = new FirefoxDriver(service, options, TimeSpan.FromSeconds(30));
There I put the binaries in D:\tmp\Binaries\ and specified it in the code to check the geckodriver there.
I kept getting this error also & the only thing I could do to finally fix it (not sure if it's the best answer for everyone who has this issue) was I placed the geckodriver.exe in my main Library directory, then I opened webdriver.py:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py
found the line where it says:
executable_path="geckodriver", firefox_options=None,
and changed it to:
executable_path="/Library/geckodriver", firefox_options=None
I was having a Visual Studio 2017 issue where the build would fail because it was looking in a non existent directory for the geckodriver exec. I also had added it using nuget pack manager. What I found was in Visual Studio->Project->Properties->Build it works if you make the build independent of the architecture: Platform target is Any CPU & either leave the other check boxes (Prefer 32-bit, Allow unsafe code, Optimize code) all unchecked or just have Prefer 32-bit checked (which is the default on my system).
btw:my Application was a .NET Framework 4.5.2 Console Application
This solution worked for me for VS2017. Just copied the geckodriver.exe to my project folder like this:
C:\Users\pedne\Desktop\C#\FirstSolution\FirstSolution\bin\Debug
I am using selenium to test our websites. When I build the project, there is an Exception :-
OpenQA.Selenium.WebDriverException: Failed to start up
socket within 45000 milliseconds. Attempted to connect to the
following addresses: 127.0.0.1:7055 and the problem is from the code
IWebDriver driver = new FirefoxDriver();
Anybody knows how to solve this problem?
Just like the other drivers available to Selenium from other browser vendors, Mozilla has released an executable that will run alongside the browser.
You can download the latest executable geckodriver from here
Add downloaded executable geckodriver to system path
The Selenium client bindings will try to locate the geckodriver (or wires) executable from the system path. You will need to add the directory containing the executable to the system path.
On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
On Windows you need to update the Path system variable to add the full directory path to the executable geckodriver. The principle is the same as on Unix.
After all above stuff you need to Initialize FireFoxDriver as below :-
var driver = new FirefoxDriver(new FirefoxOptions());
Note :- Follow this link for the solution of this problem with other programming language.
This answer didn't worked with me. Running selenium 2.53.6 and firefox 47 n 48.
I would recommend downloading firefox 46 which seems to be the best match for selenium 2.53.x.
https://ftp.mozilla.org/pub/firefox/releases/46.0.1/win64/en-US/
Once I downgraded to firefox 46.0.1 everything was working as expected.