Microsoft Edge V18363 freezes immediately after opening in a C# Selenium project - selenium

I am trying to run MS Edge using the Microsoft webdriver with Selenium. The browser starts and get stuck before opening the URL.
I have created a C# MSTest Project and added Selenium.Microsoft.Webdriver.
Afterwards, I installed Selenium.WebDriver.MicrosoftDriver.
When I now run the test, Edge starts and get stuck immediately.
The error is:
An exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:49681/session. The status of the exception was ReceiveFailure, and the message was: Die zugrunde liegende Verbindung wurde geschlossen: Unbekannter Fehler beim Empfangen.
I also tried using Selenium.Microsoft.Webdriver2 and installing the Microsoft driver using DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
Windows 10 and Edge are v18363. The zoom is at 100%

Have you installed the Microsoft WebDriver in an elevated command prompt? You should run the cmd as Administrator when you using DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0.
Besides I installed the following NuGet Packages in my project:
Then run the following code to start a test:
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
namespace ecwebdriver
{
public class webdriver
{
static void Main(string[] args)
{
var driver = new EdgeDriver();
driver.Navigate().GoToUrl("https://www.bing.com/");
var element = driver.FindElementById("sb_form_q");
element.SendKeys("webdriver");
element.SendKeys(Keys.Enter);
System.Threading.Thread.Sleep(5000);
driver.Quit();
}
}
}

Related

Selenium getting stuck on data:, (MS Edge)

I want to use Selenium to navigate to a website. Selenium opens up the browser but does not navigate further to the specified website URL, but gets stuck on the "data:," url. After some time time I get the following exception:
"The HTTP request to the remote WebDriver server for URL http://localhost:58504/session timed out after 60 seconds"
Note: I did not specify the 58504 port anymore, so I guess it is the default port that Selenium use?
I am programming in C# and using the following Nuget Packages:
https://www.nuget.org/packages/Selenium.WebDriver/4.1.1
https://www.nuget.org/packages/WebDriverManager/2.13.0
Here is the code:
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;
using WebDriverManager.Helpers;
public void VisitWebsite()
{
IWebDriver driver = null;
try
{
new DriverManager().SetUpDriver(new EdgeConfig(), VersionResolveStrategy.MatchingBrowser);
EdgeOptions options = new EdgeOptions();
options.AddArgument("--no-sandbox);
options.AddArgument("--disable-infobars");
options.AddArgument("--disable-dev-shm-usage");
options.AddArgument("--disable-browser-side-navigation");
options.AddArgument("--disable-extensions");
options.AddArgument("--dns-prefetch-disable");
options.AddArgument("--disable-gpu");
options.AddArgument("--disable-software-rastersizer");
driver = new EdgeDriver(options);
}
catch (Exception ex)
{
throw ex;
}
driver.Navigate().GoToUrl("https://www.google.com");
}
Where does it go wrong? Thanks!
I found the answer. It seems the DeveloperToolsAvailability policy for the MSEdge browser had a value that "blocks" Selenium from working. You can read more about it here: https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp#developer-tools-availability-policy

How to enable IE mode in Chromium Edge Browser in selenium C#?

I want to automate a website in Edge which is require IE mode to be enabled. How can launch Edge in IE mode in selenium?
Below code which I currently use launches Edge in non IE mode, which won't display the website properly.
Dim edgeDriverService = Microsoft.Edge.SeleniumTools.EdgeDriverService.CreateChromiumService()
Dim edgeOptions = New Microsoft.Edge.SeleniumTools.EdgeOptions()
edgeOptions.PageLoadStrategy = PageLoadStrategy.Normal
edgeOptions.UseChromium = True
Dim driver As IWebDriver = New Microsoft.Edge.SeleniumTools.EdgeDriver(edgeDriverService, edgeOptions)
driver.Navigate().GoToUrl("http://example.com")
Tried using edgeOptions.AddAdditionalCapability("ie.edgechromium", True)but it didn't work
You could refer to the section Automating Internet Explorer mode in this article about how to use IE mode in Edge Chromium in Selenium C#.
You could refer to the following steps:
Download the latest version of IEDriverServer from Selenium site. Here I use 32 bit Windows IE version 3.150.1.
Make some preparations to use IEDriver according to this.
Create a C# console project using Visual Studio.
Install Selenium.WebDriver 3.141.0 nuget package from Nuget package manager.
Add the code below to the project and modify the paths to your owns in the code:
static void Main(string[] args)
{
var dir = "{FULL_PATH_TO_IEDRIVERSERVER}";
var driver = "IEDriverServer.exe";
if (!Directory.Exists(dir) || !File.Exists(Path.Combine(dir, driver)))
{
Console.WriteLine("Failed to find {0} in {1} folder.", dir, driver);
return;
}
var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver);
var ieOptions = new InternetExplorerOptions{};
ieOptions.AddAdditionalCapability("ie.edgechromium", true);
ieOptions.AddAdditionalCapability("ie.edgepath", "{FULL_PATH_TO_MSEDGE.EXE}");
var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30));
webdriver.Url = "http://www.example.com";
}
Run the project to test:
Notes:
Make sure to close all the Edge browser tabs and window before running the code.
Use full paths in the code. For example: ieOptions.AddAdditionalCapability("ie.edgepath", #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");.

Browsers are not launching from command prompt. Same testng File is working while running through eclipse

I am trying to run my testng test cases from command prompt. I can see browser's instance are created in task manager but it is not launching with given URL. I debugged the code and found it is failing on new ChromeDriver() below line but there is no exception.
On command line, I can see below message :
Starting ChromeDriver 2.18.343845 (73dd713ba7fbfb73cbb514e62641d8c96a94682a) on port 7108
Only local connections are allowed.
Browser instance will create in task manager but it will not launch and will not go to next line.
This issue is coming from all browsers on same line.
same code worked well in Eclipse.
Using Selenium 2.53.0 and testng 6.9.13 versions
Try this solution:
ChromeDriverService service = null;
try
{
service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(chromeDriver))
.usingAnyFreePort()
.build();
service.start();
}catch(IOException io){}
if(service.isRunning())
{
DesiredCapabilities cap = DesiredCapabilities.chrome();
try{
driver = new RemoteWebDriver(service.getUrl(), cap);
}catch (SessionNotCreatedException e)
{
}
}

Firefox Failed to start up socket, using mono (c#) on windows 7

I really need help, I am new to this field.
I've created simple code on C# to open Firefox by using selenium Lib. I've done my code on Mono (Xamarin 4.0).
If I build and run my code by using .Net runtime, everything is working great. However, when I switch to Mono (3.0.6), I encounter this problem:
Unhandled Exception:
OpenQA.Selenium.WebDriverException: Failed to start up socket within 45000
at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.ConnectToBrowser (Int6
4 timeToWaitInMilliSeconds) [0x00000] in :0
Did I miss something? What should I do to solve this problem?
Thank you guys for your help.
Edit
Here is my sample code:
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Support.UI;
namespace AutomatedTesting
{
class MainTest
{
public static void Main (string[] args)
{
IWebDriver driver = new FirefoxDriver ();
driver.Navigate ().GoToUrl ("http://www.google.com");
}
}
}

No connection could be made because the target machine actively refused it(selenium)

I have extracted the following code from selenium IDE.(c# remote control)
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTests
{
[TestFixture]
public class MyFirstVCTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[Test]
public void TheNewTest()
{
selenium.Open("/");
}
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", 4444, "*chrome","http://demo.volunteercampaigns.com/");
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheMyFirstVCTest()
{
selenium.Open("/?AspxAutoDetectCookieSupport=1");
selenium.Click("link=Login");
selenium.WaitForPageToLoad("30000");
selenium.Type("id=ctl00_ContentPlaceHolder1_txtEmailAddress", "elonadminss#eeeorbees.com");
selenium.Type("id=ctl00_ContentPlaceHolder1_txtPassword", "orbs123");
selenium.Click("id=ctl00_ContentPlaceHolder1_btnlogin");
selenium.WaitForPageToLoad("30000");
selenium.Click("id=ctl00_lblUserName");
selenium.Click("id=ctl00_lnkSignOut");
selenium.WaitForPageToLoad("30000");
}
}
}
i created a webform and added a button there.
in button click event i wrote this code
SeleniumTests.MyFirstVCTest m = new SeleniumTests.MyFirstVCTest();
m.SetupTest();
m.TheMyFirstVCTest();
m.TeardownTest();
i included all .dll files. its running fine(no errors and warnings).
but after clicking button i am getting the following error
No connection could be made because the target machine actively refused it 127.0.0.1:4444
what should i do??
thanks in advance..
Note to viewers: This post may help you : No connection could be made because the target machine actively refused it
"...the target machine actively refused it" means the server could be reached and responded within the timeout, but the specified port wasn't open. This can have several reasons, e.g. a local firewall blocking the connection. Are you sure the server is listening on the right IP/port?
To add more clarity for the readers: Start selenium server using the followings basic steps:
Download selenium -server standalone from official selenium download
page.
Open command prompt.
Navigate to the folder using "Cd ".
Add this command: "java - jar ".
Hit enter.
Selenium server will be started.
I get the same error, but on a different line of code. Hopefully this might help someone somewhere even if it doesn't answer the initial question.
public override void SetupTest()
{
Driver = new FirefoxDriver();
base.SetupTest();
}
I'm using the WebDriver (I don't run the Selenium server), and the constructor of FirefoxDriver throws the Exception.
Sometimes I get this exception:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: No connection could be made because the target machine actively refused it
with this call stack:
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.ConnectToBrowser(System.TimeSpan timeToWait) Line 247 C#
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start() Line 98 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.StartClient() Line 237 C#
WebDriver.dll!OpenQA.Selenium.Remote.RemoteWebDriver.RemoteWebDriver(OpenQA.Selenium.Remote.ICommandExecutor commandExecutor, OpenQA.Selenium.ICapabilities desiredCapabilities) Line 89 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxBinary binary, OpenQA.Selenium.Firefox.FirefoxProfile profile, OpenQA.Selenium.ICapabilities capabilities, System.TimeSpan commandTimeout) Line 172 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxBinary binary, OpenQA.Selenium.Firefox.FirefoxProfile profile, System.TimeSpan commandTimeout) Line 167 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxBinary binary, OpenQA.Selenium.Firefox.FirefoxProfile profile) Line 154 C#
WebDriver.dll!OpenQA.Selenium.Firefox.FirefoxDriver.FirefoxDriver(OpenQA.Selenium.Firefox.FirefoxProfile profile) Line 132 C#
SetupTest() Line 513 C#
Sometimes I get this exception:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted
with this call stack:
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.DetermineNextFreePort(string host, int port) Line 161 C#
WebDriver.dll!OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start() Line 88 C#
[same as above]
But one thing I didn't realize at first is that if you continue execution (F5), everything is fine. The Exception must be handled in the WebDriver.
The only thing is that I had the DEBUG/Exceptions/CLR Exceptions: Thrown [checked].
Just uncheck that and everything runs without throwing/breaking. Took me a while to realize that. Leftovers of a previous debugging session...
I got this because a part of my code held a reference to a stale driver.
var driver1 = new OpenQA.Selenium.Firefox.FirefoxDriver();
driver1.Close();
driver1.Quit();
driver1.Dispose();
var x = driver1.FindElements(...);
This is the way i do it, the structure of my class.
[TestFixture, Parallelizable(ParallelScope.None)]
public class UserTest : BaseTestClass
{
[SetUp]
public void SetUp()
{
ChromeOptions options = new ChromeOptions();
//options.AddArgument("--headless");
options.AddArgument("--start-maximized");
var driver = new ChromeDriver(options);
WebDriver = WebDriverExtended.InitWebDriver(driver, driver.Url);
WebDriver.Start();
}
[TearDown]
public void Cleanup()
{
//Dispose after every single test, fixed the problem.
WebDriver.Close();
WebDriver.Quit();
WebDriver.Dispose();
}
[Test]
public void LoginTest()
{
//My test ...
}
}
I am currently using Selenium.Support v3.6.0 and Selenium.WebDriver v3.6.0.
Disposing the webdriver fixed my problem
No connection could be made because the target machine actively
refused it 127.0.0.1:4444
I also encountered this type of error.
What I was doing is I was closing the browser and quitting the driver at end of the test, but I forgot to make Webdriver wait = null;
So again when I tried to open a new browser for the next test, it will eventually start the browser and redirects to the URL but at the time of interacting it was giving me this error No connection could be made because the target machine actively refused it.
So I found that I was using wait of closed driver instance.
So please check whether you are using anything like that.
In my case it was a problem with the scope of the services. The ones that were using WebDriver were registered as singletons, and every subsequent request after the first one was failing. (even though I was closing and recreating the web driver instance manually after each request). Once I changed the scope to transient it worked fine.
Make sure the remote machine on which scripts are to be run is up and working. Secondly make sure chrome driver and chrome is update on it. Lastly no firewall is blocking ur access to remote machine.
PS: Manually close the selenium server and restart it.
For me, this problem was solved by changing settings within Chrome, as follows:
go into Chrome Menu Settings (three vertical dots / hamburger menu)
scroll down to Advanced, and expand it
System > Open Proxy Settings
UN-check "Automatically Detect Settings"