Enabling AcceptInsecureCertificates in Selenium EdgeDriver options throws an exception - selenium

Setup is Windows 10 v1903 and Visual Studio 2019 v16.2.2
I've installed the EdgeDriver using the following command:
DISM.exe /Online /Add-Capability /CapabilityName:Microsoft.WebDriver~~~~0.0.1.0
I've then created a new .NET Core console app and added the latest Selenium.WebDriver NuGet package (v3.141.0) to it. Then I've added code to Program.cs so that it looks like this:
using OpenQA.Selenium.Edge;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var edgeOptions = new EdgeOptions { AcceptInsecureCertificates = true };
new EdgeDriver(edgeOptions);
}
}
}
When I run the console app I get the following error when executing the new EdgeDriver(edgeOptions); line.
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=The specified arguments passed to the command are invalid.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at ConsoleApp1.Program.Main(String[] args) in ********\Program.cs:line 10
However if I change the value of AcceptInsecureCertificates from true to false then I get no exception and the browser opens as expected. This feels like a bug but I don't know if it's Selenium or the EdgeDriver that's at fault.

From the Microsoft Edge WebDriver document, we can see that the W3C WebDriver is still not support at present.
You could submit the Feedback at the bottom of the WebDeiver document.

Related

Appium: failed to locate open application error

I am using C#, Appium, and WinAppDriver to automate UI tests on a desktop application, however, I continue to have an intermittent issue when launching the WPF application. I have done a lot of research on this but cannot find a solid solution.
When opening the application there is a login splash screen. When the correct login credentials are entered there is another loading splash screen for approximately 5 seconds before the application opens.
I continue to get the following exception when opening the application; it appears to be random. Every time I think I found a pattern I find another data point that conflict with the pattern I thought I identified.
Exception
Message:
OpenQA.Selenium.WebDriverException : Failed to locate opened application window with appId: C:\Program Files (x86)\path to .exe\, and processId: 14124
Stack Trace:
RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
AppiumDriver`1.Execute(String driverCommandToExecute, Dictionary`2 parameters)
RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
RemoteWebDriver.ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
AppiumDriver`1.ctor(Uri remoteAddress, ICapabilities appiumOptions)
WindowsDriver`1.ctor(Uri remoteAddress, AppiumOptions AppiumOptions)
Login code
if (session == null){
AppiumOptions appOptions = new AppiumOptions();
appOptions.AddAdditionalCapability("app", Path);
appOptions.AddAdditionalCapability("platformName", "Windows");
appOptions.AddAdditionalCapability("deviceName", "WindowsPC");
Thread.Sleep(TimeSpan.FromSeconds(5));
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appOptions);
Assert.IsNotNull(session);
Thread.Sleep(TimeSpan.FromSeconds(10));
var allWindowHandles = session.WindowHandles;
session.SwitchTo().Window(allWindowHandles[0]);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(1);
//Enter password and login
session.FindElementByAccessibilityId("tbPwd").SendKeys("password");
session.FindElementByAccessibilityId("btnLogin").Click();
Thread.Sleep(TimeSpan.FromSeconds(5));
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appOptions);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(1);
}
Tear down code after each test case
public void TearDown()
{
AppiumOptions appOptions = new AppiumOptions();
appOptions.AddAdditionalCapability("app", "Root");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appOptions);
// Use the session to control the desktop
session.Keyboard.PressKey(Keys.Command + "r");
session.Keyboard.SendKeys(Keys.Null);
session.Keyboard.SendKeys(#"C:\path of taskkill file.bat"+ Keys.Enter);
//End current session instance
session.Dispose();
}

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

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();
}
}
}

Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') with IEDriver Selenium IE11

I am using VS2017 on a Win10 (17134.471) machine and I just installed Selenium. I can get Chrome, Firefox, Edge to work but not IE11 (11.471.171340). I believe that I have done all the other suggested updates but continue to get:
There are no more files.
It is not clear as to what needs to be installed I installed using NuGet and the versions are:
Selenium.WebDriver v3.141.0 (14 updates since 3.6.0.0)
Selenium.WebDriver64 v3.11.0.1
Selenium.Webdriver.MicrosoftDriver v17.17134.0
Test Name: IeMethod
Test FullName: utLearn2018.FirstTestClass.IeMethod
Test Source: C:\Users\stephan\Documents\Visual Studio 2017\Projects\utLearn2018\utLearn2018\FirstTestClass.cs : line 44
Test Outcome: Failed
Test Duration: 0:00:22.3336919
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService service, InternetExplorerOptions options)
at OpenQA.Selenium.IE.InternetExplorerDriver..ctor()
at utLearn2018.FirstTestClass.IeMethod() in C:\Users\stephan\Documents\Visual Studio 2017\Projects\utLearn2018\utLearn2018\FirstTestClass.cs:line 53
Result Message:
Test method utLearn2018.FirstTestClass.IeMethod threw exception:
System.InvalidOperationException: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:50326/' (SessionNotCreated)
My code is as follows:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.IE;
[TestMethod]
public void IeMethod()
{
InternetExplorerOptions options = new InternetExplorerOptions
{
IntroduceInstabilityByIgnoringProtectedModeSettings = true,
EnableNativeEvents = false,
EnsureCleanSession = true
};
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");
driver.Manage().Window.Maximize();
driver.Close();
driver.Quit();
}
Some version of IE driver and selenium webdriver are not compatible. Worth trying different versions of IE driver and Selenium webdriver in order to launch the IE browser.

Firefox driver is not getting launch on VM machine

1. resources I used : C# , Selenium , VS 2017, Jenkins , VM machine (windows 10) , Nunit v3.9, geckoDrive v19, firefox v56/57
2. I can execute firefox / chrome browser cases on local machine
3. I can execute chrome browser cases on VM machine
4. Issue : **I can Not execute firefox cases on VM machine and its throwing below error.**
**Error Message**
OpenQA.Selenium.WebDriverException : Cannot start the driver service on http://localhost:50352/
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
I am adding few code below where issue is throwing issue
Stacktrace
at OpenQA.Selenium.DriverService.Start()
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(String geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)
at MPAutomation.Driver.Initialize(String browser) in D:\Workspace.Automation\MPproject\MPAutomation\Utility\Driver.cs:line 79
# code on this line : Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(10));
at MPAutomation.BaseTest.Init() in D:\Workspace.Automation\MPproject\MPAutomation\Utils\BaseTest.cs:line 54
#code here : LoginPage.GoTo(Settings.BrowserType); # I am passing "Firefox"
--TearDown
at MPAutomation.Driver.Close() in D:\Workspace.Automation\MPproject\MPAutomation\Utility\Driver.cs:line 117
# Instance.Close();
at MPAutomation.BaseTest.Cleanup() in D:\Workspace.Automation\MPproject\MPAutomation\Utils\BaseTest.cs:line 97
---------------------------------------------------------------------
firefox implemnetation looks like this in Driver.cs
- I tried with various version of Firefox too but none is working on VM
else if(browser.Equals(Constant.Firefox)) {
// driver init from here
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DrivePath);
service.FirefoxBinaryPath = DrivePath;
var profile = new FirefoxProfile();
profile.AcceptUntrustedCertificates = true;
var options = new FirefoxOptions();
options.AcceptInsecureCertificates = true;
options.Profile = profile;
Instance = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(10));
Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Utility.Logger.Write("***** Firefox Browser has been initialized now *********");
}
--------------------------------
5. We have one certificate for firefox and which has already been taken care locally and on VM
6. I am not sure why automation is not able to start firefox on VM
Finally we got the solution of this issue.
We need to set up "sandbox level" for firefox on VM.
profile.setPreference("security.sandbox.content.level", 5);
https://github.com/mozilla/geckodriver/issues/466
https://wiki.mozilla.org/Security/Sandbox

Selenium and a Non-working IEDriverServer

The IEDriverServer is throwing a OpenQA.Selenium.WebDriverException when I try a simple navigation to a page. This is working for Firefox.
It is "Unexpected error" and if I read further along it appears to be a 404 page not found.
I have already disabled protected mode for all zones and had also made IntroduceInstabilityByIgnoringProtectedModeSettings = true on the InternetExplorerOptions object.
How does one get IE working in this case?
Edit
Here is the stacktrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response
errorResponse) at
OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String
driverCommandToExecute, Dictionary`2 parameters) at
OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities
desiredCapabilities) at
OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor
commandExecutor, ICapabilities desiredCapabilities) at
OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService
service, InternetExplorerOptions options, TimeSpan commandTimeout)
at
OpenQA.Selenium.IE.InternetExplorerDriver..ctor(InternetExplorerDriverService
service, InternetExplorerOptions options) at
CUWebinars.Selenium.Core.Ie.IeTestDriver..ctor() in
e:\TTS\BankWebinars\CUWebinars.Selenium.Core\Ie\IeTestDriver.cs:line
21 at CUWebinars.WebUi.Tests.Ie.IeBaseTest.Setup() in
e:\TTS\BankWebinars\CUWebinars.WebUi.Tests\Ie\IeBaseTest.cs:line 13
Edit 2
The following is in the constructor of the IeTestDriver (custom class)
const string ieTestDriverLocation = #"E:\";
var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService(ieTestDriverLocation);
var internetExplorerOptions = new InternetExplorerOptions();
internetExplorerDriverService.Port = 333; // this is the port for the driver, not the webpage
port = "5556"; // in base class
webDriver = new InternetExplorerDriver(internetExplorerDriverService, internetExplorerOptions); // crashes here
webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
webDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
The port 333 specified for the InternetExplorerDriverService falls within the well-known-port-numbers range:
On most systems, a well-known port number can only be used by a system
(root) process or by a program run by a privileged user.
Allow the driver service to select its own port by not specifying one explicitly, or provide an available port.
Double clicking IEDriverServer.exe will give you a Listening on port <number> message to see what it automatically picks up as available.