Selenium with Microsoft Edge driver never finishes initialising - c#

I'm using the C# bindings for Selenium and trying to get a simple automated test in Microsoft Edge working.
class Program
{
static void Main(string[] args)
{
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
}
}
But the program halts on the initialisation of the EdgeDriver, the edge browser launches but the url never changes to "bing.com".
Has anyone else experienced this?

I have faced the same issue. I followed the below steps to resolve it :-
Download the correct Microsoft WebDriver server version for your build.
How to find your correct build number :-
1- Go to Start > Settings > System > About and locate the number next to OS Build on the screen. This is your build number. Having the correct version of WebDriver for your build ensures it runs correctly.
2- Run this command systeminfo | findstr /B /C:"OS Version" this will give the output like OS Version: 10.0.10586 N/A Build 10586. Here is build number is 10586
You need to check your Windows OS build number and download appropriate .msi and install it.
Provide the Syetem property where MicrosoftWebDriver.exe installed to webdriver.edge.driver.
Note :- The Default installed location of the MicrosoftWebDriver.exe :-
for 64 bit is C:\Program Files (x86)\Microsoft Web Driver
for 32 bit is C:\Program Files\Microsoft Web Driver
Hope it will work...:)

This happens when your system does not match the webdriver version... Determine which release of Windows 10 you are using... then go here and download same release..
https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver
Here's what the error looks like when the versions don't match.
Selenium will Hang
EdgeOptions options = new EdgeOptions();
options.PageLoadStrategy = EdgePageLoadStrategy.Eager;
RemoteWebDriver driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this exception with Edge still up and on the Bing page
Exception Thrown
changing the code to this, with no options:
var driver = new EdgeDriver();
driver.Url = "http://bing.com/";
Results in this:
Exception thrown: 'System.InvalidOperationException' in WebDriver.dll
And this in the console.
Something's not right with the MicrosoftWebDriver.Exe which was downloaded from here. https://www.microsoft.com/en-us/download/details.aspx?id=48212 and installed into the Program Files folder by default. Here's screenshot of add/remove programs. System is Windows 10 PRO 64 bit.
Note I did not try the 32 bit version

Related

How to Create a Test Project for Winappdriver with C#

I need to learn about how to set-up a winappdriver windows app test project in visual studio and inspecting the elements for a medium size windows application.
Navigate to the WinAppDriver GitHub web page and download the latest
version. I downloaded the 1.2 version
After installation, you will find the diver at C:\Program Files
(x86)\Windows Application Driver location.
First, we need to enable Developer Mode on our Windows 10, Developer
mode is not enabled. Enable it through Settings and restart Windows
Application Driver
If you have Microsoft Visual Studio installed, you will most likely
have Element Inspector already installed on your machine
In case you do not have it installed, navigate to the Windows 10 SDK
site, download and install it.Run the inspect.exe and make sure it is
working fine
**.
Create a new NUnit test project
2- download appium dependency from NuGet
3- Update an existing UnitTest1.cs class as follows:**
using NUnit.Framework;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System
[SetUp]
public void Setup()
{
AppiumOptions Options = new AppiumOptions();
Options.AddAdditionalCapability("app", "C:\\Windows\\System32\\notepad.exe");
Options.AddAdditionalCapability("deviceName", "WindowsPC");
DesktopSession = new WindowsDriver<WindowsElement>(new Uri(DriverUrl), Options);
Assert.IsNotNull(DesktopSession);
}
[TearDown]
public void Close()
{
DesktopSession.CloseApp();
}
}
4= Run the test
Note: If some references or packages are missing, right-click on it and include it in the solution.
5- Create Windows Elements and perform actions
Open up application under test (AUT), in our case it is Notepad.exe, and Inspect.exe tool to fetch locators.
Click on the Notepad text area and find the AutomationId attribute on the right-hand side of the Inspect.exe tool.
WindowsElement NotepadTextArea = DesktopSession.FindElementByAccessibilityId(“15”);
NotepadTextArea.SendKeys(“Hello World”);
Try! try! ,Run the test! Run the test! Run the test!
#pawansinghncr's answer is correct, but I would also suggest trying out the UI Recorder, it's in the Releases page of the WinAppDriver's Github.

Playwright (.NET) tries to use different browser versions than installed

I have created some tests using Playwright with .NET bindings.
[OneTimeSetUp]
public async Task OneTimeSetUp()
{
random = new Random();
var playwright = await Playwright.CreateAsync();
browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false
});
context = await browser.NewContextAsync();
page = await context.NewPageAsync();
}
Before running tests I had run
npx playwright install
before running tests. The outcome of aforementioned command are browsers installed in path C:\Users\username\AppData\Local\ms-playwright
When running tests however, error is thrown:
OneTimeSetUp: Microsoft.Playwright.PlaywrightException : Executable doesn't exist at C:\Users\11033414\AppData\Local\ms-playwright\chromium-907428\chrome-win\chrome.exe
so it seems like playwright wants to use other versions of browsers than installed ones.
How to make Playwright point to correct versions of browsers installed?
# Install the CLI once.
dotnet tool install --global Microsoft.Playwright.CLI
# Install the browsers
playwright install
(The current error description is a bug in 1.14, it gets fixed with 1.15.)
According to: https://github.com/microsoft/playwright-dotnet/issues/1638#issuecomment-887340857
the workaround is to use dotnet .\bin\Debug\net5.0\Microsoft.Playwright.dll -- install.
I've tried this and it works for me.

Selenium IEDriver / Firefox Driver browser location Error

unexpectedly I am experiencing this issue. I am trying to run my testcase. For Firefox or IE browser but I don't know where is the issue. It cannot find the browser location.
Selenium.WebDriver -Version 2.52.0
Selenium.Support -Version 2.52.0
Selenium.RC -Version 2.52.0
Selenium.WebDriverBackedSelenium -Version 2.52.0
It was working perfectly but soon after I updated my nupackages. I am having this issue. Also I tried to use previous version but now I am having same problem in that one as well.
Error:
IEDriver
FirefoxDriver Error
Enviorment Variable
Installed Location:
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
C:\Program Files\Mozilla Firefox\firefox.exe
Make sure you're mentioning path of IEDriverServer executable in PATH variable of your system.
echo $PATH
https://github.com/SeleniumHQ/selenium/wiki/FirefoxDriver
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
It happened to me as well. I tried to download older version from the below link and it worked. Let me know, if that helped. About IE I am trying to figure it out what should be the case.
Firefox version download
You don't need to alter your code. Also Anderson is right you probably might have downloaded x64 version and I think Selenium might be trying to find x86 version (in Program File) which might have caused the problem.
For IE Driver download it (32bit) LINK
After that your browser init need to be something like that:
InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
driverService.LibraryExtractionPath = #"c:\drivers\"; // here is your driver location
InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = true;
options.IgnoreZoomLevel = true;
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
driver = new InternetExplorerDriver(driverService, options, TimeSpan.FromSeconds(180));
For Firefox just try to update the firefox to last version.

OperaDriver not working

Using Selenium Grid2 and RemoteWebDriver in an MSTest class, I am struggling to get OperaDriver working.
I create the Selenium hub and Opera node by running the following commands in CMD:
start java -jar selenium-server-standalone-2.30.0.jar -role hub
start java -jar selenium-server-standalone-2.30.0.jar -role node -port 7001 -browser "browserName=opera,version=11.62,maxInstances=5,platform=WINDOWS" -hub http://localhost:4444/grid/register
And this works fine, I can the see the registered node when I view my hub in a browser.
But I get an exception whenever I try to create a new WebDriver in my C# test class:
DesiredCapabilities operaCapabilities = DesiredCapabilities.Opera();
operaCapabilities.SetCapability(CapabilityType.BrowserName, "opera");
operaCapabilities.SetCapability(CapabilityType.Platform, "WINDOWS");
operaCapabilities.SetCapability(CapabilityType.Version, "11.62");
operaCapabilities.SetCapability("opera.binary", "C:\\Program Files\\Opera\\opera.exe");
operaCapabilities.SetCapability("opera.port", 7001);
RemoteWebDriver operaDriver = new RemoteWebDriver(operaCapabilities);
Actually I get two different exceptions - the first time after creating the hub and node in Selenium I get this:
Could not find a platform that supports bundled launchers, please set
it manually
Build info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19
00:15:27'
System info: os.name: 'Windows 8', os.arch: 'x86', os.version: '6.2',
java.version: '1.7.0_15'
Driver info: driver.version: OperaDriver
And everytime after that I get the following error:
Could not initialize class
com.opera.core.systems.runner.launcher.OperaLauncherRunner
I am using Selenium-standalone-2.30.0.
I was using Opera version 12.14 but downgraded to 11.62 after I saw a list of compatible versions on the OperaDriver wiki page but the errors remain the same.
I have tried initialising the RemoteWebDriver with and without the capabilities above and get the same result every time.
Does anyone know what the problem is here and how to get a RemoteWebDriver working with Opera in this way?
Edit: Could it be that the platform for Opera version 12.14 reads as 'WINDOWS 8', and version 11.62 reads as "WIN32" when I open the Opera browser and view Help => About? As I am specifying the platform as WINDOWS in the node and RemoteWebDriver. If I try to specify WINDOWS 8 as the platform for the RemoteWebDriver an new exception is thrown where it can't find matching enum:
org.openqa.selenium.WebDriverException:
java.lang.IllegalArgumentException: No enum constant
org.openqa.selenium.Platform.WINDOWS 8
Edit2: For some reason CurrentPlatform is returning Vista for me, even though I am running Windows8.
Platform platform = Platform.CurrentPlatform;
And I also noticed that the OperaDriver source code checks for 'VISTA' in uppercase whereas the Platform in C# reads as 'Vista'.
Could this be causing the problem?
I've been suffering from this problem as well and thanks to the hint from eviltester I was able to solve the issue by using the following command line to start the selenium server:
java -Dos.name=windows -jar selenium-server-standalone-2.32.0.jar
The use of -Dos.name=windows is the equivalent of System.setProperty("os.name", "windows") and will allow your C# selenium code to work for the Opera browser.
I saw this when running in Java. In debug mode it looked like a possible omission in OperaLauncherRunner.java launcherNameForOS does not cater for the WIN8 enum returned by Platform.getCurrent().
In Java I fudged it by setting the system property "os.name" to "windows" before creating a new OperaDriver. This forced the Platform.getCurrent to return XP which the opera launcher was happy with.
So in java I just used this hack:
System.setProperty("os.name","windows");
driver = new OperaDriver();

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