For an automation project I have to use selenium webdriver with edge. Unfortunately the site is under IE kernel. So I start edge in IE mode everything works fine. But when the controller needs to detect a new window with windowHandle, it does not detect anything new even with a wait.
Is it possible to make the switch work in IE mode ?
PS: As I use an IE driver I can by changing a few lines start IE. When I run IE the window change is done. When I run Edge with the options I don't detect anything. So everything works fine with the IE browser, the problem only comes from edge and the IE mod.
I am using an IE driver with capabilities like this :
var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver);
var ieOptions = new InternetExplorerOptions{};
ieOptions.AddAdditionalCapability("ie.edgechromium", true);
ieOptions.AddAdditionalCapability("ie.edgepath", "{path to msedge.exe}");
var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30));
driver.FindElement(By.Id("button")).Click();
Thread.Sleep(2000);
string popupHandle = string.Empty;
ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
foreach (string handle in windowHandles)
{
if (handle != existingWindowHandle)
{
popupHandle = handle;
break;
}
}
driver.SwitchTo().Window(popupHandle);
Now it is solved. You can download latest Selenium version 4.0 and start scripting for Edge in IE Mode. You can also follow the issue ticket in github in the following link MS Edge in IE Mode
Related
I have a requirement to switch from chrome to edge driver chromium
I am having issues trying to launch the browser as a different user. We need to open the browser with different users who have different roles and validate
To manually do this you would right click edge browser > shift and click Microsoft edge > Run as different user
I am using the following NuGet Packages:
MicrosoftEdge.SeleniumTools 3.141.2
Selenium.Webdriver 3.141.0
Microsoft Edge version
91.0.864.54
Previously with using chrome and the package Selenium.Chrome.Webdriver i was able to use the following
service.StartupDomain = ""
service.StartupUserName = ""
service.StartupPassword = ""
service.StartupLoadUserProfile = true;
However with MicrosoftEdge.SeleniumTools 3.141.2 i am unable to find a similar solutions. Does anyone know an equivalent solution?
Current code below
EdgeDriverService service = EdgeDriverService.CreateChromiumService(driverpath, msedgedriverExe);
var edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
service. ???
edgeOptions. ???
IWebDriver driver = new EdgeDriver(service, options)
I am using the below VB.NET code op open Edge Chromium(In IE Capability Mode). It works if there are no existing Edge windows open, Other wise, it just opens another tab in the existing window and just displays This is the initial start page for the WebDriver server. and nothing happens (see screenshot below)
Dim ieService = InternetExplorerDriverService.CreateDefaultService(Environment.CurrentDirectory, "IEDriverServer.exe")
Dim ieOptions = New InternetExplorerOptions
ieOptions.IgnoreZoomLevel = True
ieOptions.AddAdditionalCapability("ie.edgechromium", True)
ieOptions.AddAdditionalCapability("ie.edgepath", "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")
Dim driver = New InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(60))
driver.Navigate().GoToUrl("https://example.com")
After one minute, it throws below exception at the line Dim driver = New InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(60))
OpenQA.Selenium.WebDriverException: 'The HTTP request to the remote
WebDriver server for URL http://localhost:52074/session timed out
after 60 seconds.'
Do anyone know how to fix this? (I don't want to kill edge sessions first and then start, because i want the are existing edge windows untouched)
To automate Edge-IE in already opened Edge browser window. Please follow the below steps
Include the application you are trying to launch in Edge-IE browser to the compatibility list of Edge browser(edge://compat)
Include the below command line to start an Edge process before calling Edge-IE driver initialization
code sample
System.Diagnostics.Process.Start(#"msedge.exe", "https://google.com/");
Thread.Sleep(1000);
var dir = "//path of your Edgedriver";
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);}
var ieService = InternetExplorerDriverService.CreateDefaultService(dir, driver);
var ieOptions = new InternetExplorerOptions { };
ieOptions.AddAdditionalCapability("ie.edgechromium", true);
ieOptions.AddAdditionalCapability("ie.edgepath", #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");
InternetExplorerDriver webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromMinutes(3));
I use Selenium ChromeDriver to open chrome browser and load a site into it programmatically.
I install selenium & ChromeDrive from this NuGet
Install-Package Selenium.WebDriver -Version 3.141.0 Install-Package
Selenium.WebDriver.ChromeDriver -Version 77.0.3865.4000
I have some questions:
if target pc has no chrome browser installed then how can i capture it by ChromeDriver ? is it possible?
when i am opening chrome browser by ChromeDriver instance then browser is opening chrome browser with a site but another CUI window is getting opened which i do not want to visible or i want to hide this CUI window. if it is not possible then how could i open this CUI window in minimize state?
a sample CUI window screen shot attached below when i work with FirefoxDriver. the same occur when i work with ChromeDriver instance.
when i executing this code chromeDriver.Close(); then opened chrome browser is getting closed but CUI window is still open. so if i click 5 times on open button then 5 CUI window is getting open along with 5 chrome browser instance which i had to close manually ....which i do not want to manually close it rather i want to close it when browser will be closed....how to achieve it ?
how to capture from code that opened chrome browser is close by this code chromeDriver.Close(); or if user click on cross button of chrome browser to close it?
how to open a new tab in already opened chrome browser instead of opening new chrome browser instance. if no chrome browser is open at all then new chrome browser will be open...how to achieve it by code. this below code opening new chrome browser always....what to change there for my point 5
chromeDriver = new FirefoxDriver(options);
chromeDriver.Navigate().GoToUrl("https://www.google.com");
another issue occur when i work with chrome driver that. it open chrome browser but a notification appear on browser like Chrome is being controlled by automated test software
I search google to hide it and found people said to use this option
options.setExperimentalOption("excludeSwitches", new String[] { "enable-automation" });
at my end this function does not available setExperimentalOption so what to do?
Please answer point wise with sample code.
For question 2,3 you can use below code
(use DriverService.Dispose(); to manually dispose driver service) :
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace MyProject
{
public class Browser : IDisposable
{
bool disposed = false;
IWebDriver Driver;
public Browser()
{
//Chrome Driver copied on startup path
ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath, "chromedriver.exe");
//hide driver service command prompt window
driverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
//hide browser if you need
//options.AddArgument("headless");
//or this to hiding browser
//options.AddArgument("--window-position=-32000,-32000");
//On offer Dona bhatt for disable automated test notification
options.AddExcludedArgument("enable-automation");
//options.AddArgument("disable-infobars");
Driver = new ChromeDriver(driverService, options);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
Driver.Close();
Driver.Quit();
Driver.Dispose();
DriverService.Dispose();
}
disposed = true;
}
//this method for navigation
public string Navigate(string url)
{
string page = string.Empty;
try
{
Driver.Navigate().GoToUrl(url);
page =Driver.PageSource;
}
catch
{
}
return page;
}
//this method for wait to an element be visible by element ID
private void WaitUntilLoad(string id, int timeOut)
{
WebDriverWait waitForElement = new WebDriverWait(Driver, TimeSpan.FromSeconds(timeOut));
try
{
waitForElement.Until(ExpectedConditions.ElementIsVisible(By.Id(id)));
}
catch (WebDriverTimeoutException e)
{
}
}
}
}
Use this class:
using(Browser brw=new Browser())
{
string pageSource=brw.Navigate("My URL");
}
I couldn't post this as a comment because it's too long. I think this question is off topic but I just noted my comments on your items...
This seems to be much to broad. Are you having a problem with any specific issue? All of these seems like things you can research and find out.
1) The chrome driver has to be downloaded and shipped with your app.
2) It might be possible to hide that window but not sure why that would be a hard requirement. I'm going to just say that you can't by default prevent the window from showing.
3) You're going to have to close the chrome windows through your .net code. Selenium isn't going to be graceful enough to terminate all the chrome windows.
4) I'm not sure what you're asking for. What's the problem?
5) I think tabs might be done very differently between browsers, it might not be something natively supported in selenium. There might be some chrome driver commands that can facilitate but I have no idea what they are.
6) Again, this is typically not the preferred experience, I'm guessing one of your packages has a different featureset than whatever you're reading was using.
I have a Selenium suite which has 150 test cases. The test has to run in Incognito mode in Chrome Browser.
I am able to launch the browser in incognito Mode. But the issue is the browser is not getting maximized ( say for 10 test cases and for remaining 140 test cases the browser launches in maximized mode) , though there is a code to maximize the browser.
As a result of this, some of the test fails ( All 10 test ).
Below is my code
desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
break;
Is there a way to ensure that the browser always (100%) launches in maximised mode.
The click operation fails when the browser is not maximised.
System.InvalidOperationException: unknown error: Element is not clickable at point (886, 466). Other element would receive the click:
For this reason, I want to run in maximised mode. In maximised mode, I am not getting this error. Please help .
Thanks
Try this code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--incognito");
IWebDriver driver = new ChromeDriver("C://",options);
It works for me
Could do something like this:
desiredCapabilities = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument("--start-maximized");
desiredCapabilities.SetCapability(ChromeOptions.Capability, options);
webDriver = new MyWebDriver(new Uri(gridHubURL), options.ToCapabilities(),TimeSpan.FromSeconds(ApplicationConfiguration.RemoteDriverTimeOutValue),testContext);
webDriver.Manage().Window.Maximize();
break;
It will need to be after the webDriver opens up, but it will maximize the window for you.
Try this instead, I have tested and should be fine
var caps = DesiredCapabilities.Chrome();
var options = new ChromeOptions();
options.AddArgument(#"--incognito");
options.AddArgument(#"--start-maximized");
caps.SetCapability(ChromeOptions.Capability, options);
var webdriver = new ChromeDriver(options);
webdriver.Navigate().GoToUrl("http://yourURL.com");
webdriver.Manage().Window.Maximize();
An alternative would be to set the initial size:
options.AddArgument("--window-size=1024,768");
You could also set some extreme values. The window should then have the size of the screen since the OS limits it (at least on Windows) :
options.AddArgument("--window-size=32000,32000");
I am running coded ui test in Chrome browse.In Web application we have one link in grid and we have to click on that link. Same test is working fine in IE but in Chrome it is giving excpetion playback can not find control with technology name=MSAA and Control type=window
i have used below code:
if (ConfigurationManager.AppSettings["Driver"] == "IE")
{
BrowserWindow br = new BrowserWindow();
HtmlHyperlink href1 = new HtmlHyperlink(br);
href1.SearchProperties.Add
(
HtmlHyperlink.PropertyNames.InnerText,
"link"
);
Mouse.Click(href1);
}
else
{
BrowserWindow br = new BrowserWindow();
string CT = br.ControlType.ToString();
string Tn = br.TechnologyName.ToString();
UITestControl Window = new UITestControl(br);
Window.TechnologyName = "MSAA";
Window.SearchProperties[UITestControl.PropertyNames.Name] = "link";
Window.SearchProperties[UITestControl.PropertyNames.ClassName] = "standardURL";
//link
UITestControl link = new WinHyperlink(Window);
link.SearchProperties[UITestControl.PropertyNames.ControlType] = "Window";
Mouse.Click(link);
}
In IE execution that link is serchable and clickable with property innertext but in chrome it is not...also tried adding friendlyname but no luck..please suggest....Now i am in impression is like whether coded ui runs in chrome or not
You cannot record coded UI tests using Google Chrome or Mozilla Firefox browsers. To play back tests on non-IE web browsers, you must install the Selenium components for Coded UI Cross Browser Testing.
https://msdn.microsoft.com/en-us/library/jj835758.aspx