Is there a way to activate IE mode in Edge Options? - c#

Hello,
I want to achieve this by having an option inside the EdgeDriver but I cant seem to find it anywhere on the map?
I am trying to open a page in IE mode inside Edge with Selenium and EdgeDriver.
Is there a way to achieve this great thing? [pun intented]

I can see 2 questions in this thread.
Is there a way to activate IE mode in Edge Options?
There is no way to activate IE mode bypassing the Edge options parameter in the Selenium Edge driver.
I am trying to open a page in IE mode inside Edge with Selenium and EdgeDriver. Is there a way to achieve this great thing?
Yes, it is possible to automate the IE mode in the new MS Edge browser using the Selenium web driver.
The new Microsoft Edge allows you to run IE11 validation for legacy sites in addition to your modern experiences. To run your IE11 tests in Microsoft Edge, download the IEDriverServer from Selenium. Then you must pass in a capability to put Microsoft Edge into IE Mode and then run your tests.
Because this capability puts the whole browser into IE11 Mode, you cannot simultaneously test content that should render in the modern Chromium engine, but you should be able to run all of your IE11 tests and validate the rendering in Microsoft Edge. Note that this code requires an update to IEDriverServer which should be included in the next release of Selenium.
After you download the new IEDriverServer from SeleniumHQ and follow the directions for the “Required Configuration” as documented here, you can run the following code to launch the new Microsoft Edge in IE11 mode and run some tests:
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", #"\\msedge.exe");
var webdriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(30));
webdriver.Url = "http://www.example.com";
}
Output:
Notes:
Make sure you are using the latest version of the IE driver server.
I suggest making a test with the latest version of the Stable Edge browser.
Try to pass the full path of the Edge browser in the 'ie.edgepath' capability. For example:
ieOptions.AddAdditionalCapability("ie.edgepath", #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");
Make sure you close all the already opened instances and tabs of the Edge browser before running the code. Otherwise, it will generate an error.
References:
Scroll to the Automating Internet Explorer mode point in this link.
kypflug/webdriver-edge-ie-mode.cs

Below code (which is in VB.NET, but you can easily modify it to C#) will start Chromium Edge in IE Mode
Dim ieService = InternetExplorerDriverService.CreateDefaultService("DIRECTORY_PATH_HAVING_IEDriverServer.exe", "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")
You can download IEDriverServer from https://www.selenium.dev/downloads/

Related

automate the edge update using selenium

Is there anyway to update the new edge browser using selenium web driver? Can we do it by setting any option or capabilities?
My present code:
EdgeOptions op= new EdgeOptions();
op.UseChromium = true;
op.BinaryLocation = #"msedge.exe";
var msedgedriverDir = #"webdriver location";
var driver = new EdgeDriver(msedgedriverDir, op);
driver.Navigate().GoToUrl("my site");
I try to search online and on this site for a solution but did not get any working solution.
We can use the Selenium web driver to automate the websites. We cannot access the update related settings of the Edge browser using the selenium web driver. So we cannot update the Edge browser by using the selenium web driver.
If you want to control the Edge updates for many users then you can try to deploy the Edge browser using Configuration Manager and try to manage updates by using it.
For a single user, by default Edge will download and install the updates automatically. You can control the updates using group policy.

Selenium tests open IE in background on TFS build server

we are trying to use Selenium for testing our MVC application. On localhost in VS2017 , it´s running correct, the tests open IE, run the test and then close the IE.
On TFS build server, the tests start IE somehow on background (in Task manager I see two iexplorer.exe processes), but the window of IE is not visible. The tests find elements, but they are not able to write text in textbox, always get error like "Element cannot be interacted with via the keyboard because it is not focusable"
Localy I run Win10 and IE11, TFS build server run Windows Server 2012 R2 and IE11 .
//initialize driver in test constructor
InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.RequireWindowFocus = true;
driver = new InternetExplorerDriver(options);
driver.Manage().Window.Maximize();
//test itself
driver.Navigate().GoToUrl(appURL);
var x = driver.FindElement(By.Id("FiltrADuvodDotazu_DuvodDotazu"));
x.SendKeys("Automatizovaný test"); //here I get error
Is there way to run IE visibly, so the tests can interact with it?
I guess your agent run as a service and this is the reason the tests run on "headless mode" (and IE not supports it, like mentioned in the comments).
To solve it you need to configure the agent as an interactive process with auto-logon enabled.
When configuring the agent, select 'No' when prompted to run as a service. subsequent steps then allow you to configure the agent with auto-logon.
More info you can find here.

How to open the Default Chrome Profile through Selenium, ChromeDriver and GoogleChrome

I want to load a new Selenium ChromeDriver that is using Chrome as if I open Chrome from my dock (Essentially it'll have all my extensions, history, etc.)
When I use the following code:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
It loads the Chrome browser with me signed into my Gmail and with all my extensions, just like I want, but the rest of my code:
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
doesn't execute. But when I use the following
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
The rest of my code executes perfectly (Notice the 'Default' added to the end of the first Argument). Any tips or suggestions on how I can get the first block of code (The one without 'Default' on the end) to execute the rest of my program would be great. Thanks!
I know this is an old question, but what worked for me is to do remove the "C:\" and replace all of the backslashes with forward slashes. So, with that from the original question, this should work to load the default profile:
options.AddArgument("user-data-dir=/Users/User/AppData/Local/Google/Chrome/User Data");
The Default Chrome Profile which you use for your regular tasks may contain either/all of the following items:
History
Bookmarks
Cookies
Extensions
Themes
Customized Fonts
All these configurations untill and unless are part of your Test Specification it would be a overkill to load them into the session initiated by Selenium WebDriver. Hence it will be a better approach if you create a dedicated New Chrome Profile for your tests and configure it with all the required configuration.
Here you will find a detailed discussion on How to create and open a Chrome Profile
Once you have created the dedicated New Chrome Profile for your tests you can easily invoke the Chrome Profile as follows:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
Here you will find a detailed discussion on How to open URL through default Chrome profile using Python Selenium Webdriver
I have the same issue. I don't know how to fix it, I guess the root cause is white space in profile path.
I know a workaround for this. Just copy the C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data to c:\myUserData (no space in the path).
Then add the argument.
options.AddArgument("user-data-dir=C:\\myUserData");
This is an Old question, but if you are facing this issue, all you have to do is close all tabs, Just shut down the chrome window..
Selenium can't use the data since it is already in use.
Hope you fond this helpful.

Selenium Firefox Preference Changed but not Applied

I am using Selenium and Firefox for automated testing, and I need the files to download automatically. Here are two links that I've used to setup my code.
Auto download PDF in Firefox
Set Firefox profile to download files automatically using Selenium and Java
To summarize the articles, the code should look like this:
FirefoxOptions options = new FirefoxOptions();
options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\Windows\\temp");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
options.setPreference("pdfjs.disabled", true); // disable the built-in PDF viewer
WebDriver driver = new FirefoxDriver(options);
When I run my test, the auto-download fails. I checked in the about:config and the settings have been changed as intended by the code.
(about:config screenshot)
Also, within that driver instance, if I change any setting and then reapply the same setting, the auto-download works. Is there a setting or step with the webdriver that I'm missing that then applies the new settings?
Here are the Selenium, Firefox, and GeckoDriver versions I've tested with:
Selenium: v3.12.0
Firefox: 59.0.3, 60.0.1
GeckoDriver: v0.19.0-win64, v0.20.0-win64, v0.21.0-win64
As far as i know is pretty difficult download files with selenium because the browser open some dialogs that is not possible control from javascript. Watch this link, I hope will be useful

Selenium: switch tab in RemoteWebDriver with C#

Currently, I'm trying to run my Selenium tests on Safari using Selenium Grid and RemoteWebDriver. This is my setup:
Mac OS Sierra 10.12.6 as a machine for running tests.
Selenium server 3.5.3.
Safari 11.
C# Selenium WebDriver and Selenium Support (latest version).
I'm using port forwarding on my host OS (Windows 10) to forward requests to Mac, running on my Virtual Machine. On my Mac I have Selenium Grid hub, which I run like this:
java -jar selenium-server-standalone-3.5.3.jar -role hub -port 4723
Also, there is a node:
java -jar selenium-server-standalone-3.5.3.jar -role node -hub http://10.0.2.15:4723/grid/register
In code, I start my driver like this:
SafariOprions options = new SafariOptions();
IWebDriver driver = new RemoteWebDriver(new Uri(hubURL), options.ToCapabilities());
My tests are running fine with current setup. But when it comes to clicking a link with attribute target='_blank' I'm starting to face some troubles. For other drivers, which I run locally, I can switch tab without any trouble: I'm getting driver.WindowHandles before I click a link, then I click a link and again retrieve Window Handles to compare with previous handles. After that I use driver.SwitchTo().Window(newHandle) and everything is ok.
But when it comes to RemoteWebDriver (or SafariDriver from Apple, I cannot say more precisely) I'm always getting only one Window Handle, even if the new tab is opened and i can see it.
I'm trying to avoid switching tab with "Command + T" as one of solutions suggested, because my tests are meant to be run on all browsers (Chrome, Firefox, Opera, Edge, Safari) and this wont work.
UPDATE: I've tried running Chrome and other browsers in Selenium Grid via RemoteWebDriver and I can say that this is not an issue of RemoteWebDriver. Next, I've installed Visual Studio for Mac and rewrite several things to run my tests without Selenium Grid, just using this code:
//if memory serves, just like this
SafariOptions options = new SafariOptions();
SafariDriver driver = new SafariDriver(options);
But, unfortunately, this didn't help. Driver navigated me to the page, clicked the link and opened a new tab, but without any switch. When I checked for driver.WindowHandles I've only got one, although there was two visible tabs. Neither driver.SwitchTo().ActiveElement nor driver.SwitchTo().Frame(hardcoded_frame_name) doesn't seem to work. Pretty long waits (for 60 seconds after opening the link and another one after that) aren't working too. Now I think that this is really a bug and I will try to report this to Apple as soon as I can.
But for now, maybe someone has a fancy workaround for this?
As we discussed in the comments, it seems to be a timing issue. So we will induce
WebDriverWait to sync up with the trailing Browser instance. I am providing a code block as a solution through Selenium-Java, consider implementing it in C# and update me if it works for you.
driver.get("http://www.google.com");
System.out.println("Page Title is : "+driver.getTitle());
String parent_window = driver.getWindowHandle();
((JavascriptExecutor) driver).executeScript("window.open('http://facebook.com/');");
WebDriverWait wait = new WebDriverWait(driver,3);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
Set<String> allWindows_1 = driver.getWindowHandles();
ArrayList<String> tabs = new ArrayList<>(allWindows_1);
driver.switchTo().window(tabs.get(1));
wait.until(ExpectedConditions.titleContains("Facebook"));
System.out.println("First Child Handle : "+driver.getTitle());
I could help you with the Java version:
After the actions done, do this below.
//Store the parent window
String parentWindow = driver.getWindowHandle();
//Open a new Windows(Mailtrap)
String a = "window.open('https://mailtrap.io/signin','_blank');";
((JavascriptExecutor)driver).executeScript(a);
//This Thread.sleep is useful with Safari. Do not remove.
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Take control over new browser
for(String handle: driver.getWindowHandles()){
driver.switchTo().window(handle);
}

Categories