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
This question already has an answer here:
"OsProcess checkForError : CreateProcess error=193, %1 is not a valid Win32 application" while starting Internet Explorer through Java and Selenium
(1 answer)
Closed 2 years ago.
I am getting this error when I try to launch IE from selenium code.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 800700C1 ('%1 is not a valid Win32 application.') for URL 'http://localhost:4593/'
code
public class Simple {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.ie.driver", "./UpdateSyncRate/Library/drivers/IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().deleteAllCookies();
driver.get(URL);
driver.manage().window().maximize();
}
}
%1 not a valid win32 application makes me think there's a problem with your exe. Potential the wrong one or the wrong version?
Have a look at WebDriverManager.
Instead of downloading and mapping drivers manually, it can do it at runtime for you:
WebDriverManager.iedriver().setup();
WebDriver driver = new InternetExplorerDriver();
There's more options you can do. Have a look at their docs.
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();
}
}
}
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"
I tried to google, but there are many different ways to work with Selenium. I'm using:
- Windows 2003 Server
- Visual Studio 2008
- Selenium IDE installed through Firefox
- NUnit 2.5 is copied into C:\
- Selenium RC is copied into C:\
First I created a Library Project using C#.
And this my class :
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium;
namespace SeleniumTest
{
[TestFixture]
public class NewTest
{
private ISelenium selenium;
private StringBuilder verificationErrors;
[SetUp]
public void SetupTest()
{
selenium = new DefaultSelenium( "localhost", 4444, "*iexplore", "http://localhost:4444" );
selenium.Start();
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
selenium.Stop();
}
catch( Exception )
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual( "", "" );
}
[Test]
public void TheNewTest()
{
selenium.Open( "/google.com" );
}
}
}
Next add all references from the C:\Selenium RC\selenium-dotnet-client-driver-1.0.1
Compiled the Library Project, succeeded. No errors.
Run NUnit.exe, now errors :(
SeleniumTest.NewTest.TheNewTest:
Selenium.SeleniumException : XHR
ERROR: URL =
http://localhost:4444/google.com
Response_Code = 403 Error_Message =
Forbidden+for+Proxy
You are getting the Forbidden error because you are setting the baseURL to that of Selenium RC. You need to set it to http://www.google.com and then in your test would look like
[Test]
public void TheNewTest()
{
selenium.Open( "/" );
}
or you need to change your test to
[Test]
public void TheNewTest()
{
selenium.Open( "http://www.google.com" );
}
to setup ide for selenium in conjunction with c# is to use visual studio express. And you can nUnit as the testing framework. Below links provide you more details
How to setup C#,nUnit and selenium client drivers on VSExpress for Automated tests
Creating Basic Selenium web driver test case using Nunit and C#
Create Unit testing project
Add library project to your solution.
right click on library project select NuGet package option.
search selenium install first two options selenium and selenium support class.
Also download chrome driver, IEDriver, gecko driver if you want to perform cross-browser testing.
create the test class and test method in the unit testing project.
[TestClass]
// ReSharper disable once InconsistentNaming
public class Test class
{
[TestMethod]
public void LoginTest()
{
// code
}
}