IE Windows Security dialog appears to block Selenium navigation - c#

I am using Selenium in C# on Windows 10. The site under test should challenge with a Windows Security login box in IE, which it does. But the login box appears to block the call.
var home = "https://site.under.test.com/";
driver = new InternetExplorerDriver(AppDomain.CurrentDomain.BaseDirectory);
driver.Url = home;
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl(home + "secure/");
//code to handle login box goes here, never gets executed unless the dialog box
//is manually addressed or something times out in GoToURL(),
//and then the dialog box doesn't work.
The login box appears:
Click here for screenie of the login box
But the execution is stalled on the GoToUrl() call:
Click here for screenie of execution
Doesn't matter what code I place after this to handle the popup, execution is blocked until something times out inside GoToUrl().
Is this expected behavior? How does one get around it?
Clarification: The problem is not how to enter data into the popup. It is about the code execution not advancing to the point where I can enter data into the popup without intervention or timeout.
This works on Win8.1, but not on Win10

The Webdriver no longer officially supports Basic Authentication. It has been removed from the Java code and the .Net version works accidentally. From my experience you can expect it to work (for now) on Win7-8.1, but not on Win10
This from Selenium support:
The support of authentication dialogs was removed from the java bindings with this commit.
I am surprised, they are still present in the c# binding, because there is no support for basic authentication in the webdriver specification.

Not sure if you found the answer yet but here is what I found so far.
.GoToUrl waits for the page to load and since the page has not loaded yet, it waits and waits and throws exception.
You can enter the url usign Javascript. Below for is .Net code for it
string script = "window.location = \'" + url + "\'";
((IJavaScriptExecutor)driver).ExecuteScript(script);
You have to manage your own wait after using the above code.
And Selenium still doesnt work with the Windows Security dialog that you see after this (Or, I havent found any info anywhere that shows how to make Selenium work with this dialog)
The best solution I have found so far is to use AutoIT, and use TAB commands within AutoIT to enter username, move to password adn enter password and then do tab tab until you get to submit button and then click on this location. Please comment here if you have found any better solution than this until now

Related

Multiple IE web-drivers : session lost when click link/button that opens a popup window

I run multiple (2) IE web-drivers together.(for user side and admin side tests)
When the InternetExplorer WebDriver click on link/button that opens an modal popup, login page are opened on new window (abnormal).
When the ie webdriver popup the window , I can see for a fraction of a second the correct address the browser should load (in URL line) , but immediatly it changed to the login url, and required enter username and password.
I found the same problem in this link,
I made the solution there, but I still have not solved the problem, and I get an entry window instead of the expected window.
see this screenshot
My IE version is 11.
My Selenium.WebDriver is 3.141.0.0
My ie webdriver is IEDriverServer_x64_3.141.5
My InternetExplorerOptions:
private static InternetExplorerOptions ieOptions = new InternetExplorerOptions
{
EnsureCleanSession = true ,
EnableNativeEvents = true ,
RequireWindowFocus = true ,
EnablePersistentHover = true ,
ForceCreateProcessApi = true ,
BrowserCommandLineArguments = "-framemerging -private"
};
I added the registry keys:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FrameMerging\(DWORD)00000000
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\TabProcGrowth\(DWORD)00000000
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE\iexplorer.exe\(DWORD)00000000
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE\iexplorer.exe\(DWORD)00000000
Edited:
By the Deepak-MSFT references, I understand that the issue caused by more than one IE web-driver instances.
I tried to kill the IE driver also by adding the ConfirmCleanSession = trueoption to the code, and also manually by running of the following statements from the command line (before running the test);
taskkill / F / IM iexplore.exe / T
taskkill / F / IM IEDriverServer.exe / T
But it did not help once I set 2 IE web-drivers to work together.
(When I tried to run the test only on one driver - it worked great!)
I would appreciate help in solving the problem!
This issue is due to a quirk of IE itself and how the driver creates the popup window for the browser.
The workaround is to ensure there are no iexplore.exe processes running when you start the session with the driver.
References:
(1) session cookie lost when click made to a link that opens a window with window.open()
(2) session cookie lost when click made to a link that opens a window with window.open()
My Solution:
Split the test case into two tests:
First Test -
Use the IE web-driver for the first site (in my case - the admin side), and parallel use another web-driver (which does not cause problems like Chrome web-driver) for the second site (in my case - the admin side)
And a second test-
Use the other web-driver above for the first site, and parallel use the IE web-driver for the second site.
So I covered the tests in IE for the two sites.

How to automatically accept Chrome's "Always open these types of links in the associated app" dialogs in Selenium

I'm automating tests using Selenium and C# and I need to open an external app from the browser. The problem is, I always get this notification and it blocks the test execution.
Does anyone know how to deal with this?
Chrome stores the settings for the acceptance of protocol handlers in the user profile. When running Chrome from Selenium, Chrome doesn't seem to use the standard Chrome user profile by default, and instead uses some default settings that are not persisted.
To get around this, you can launch Chrome from the command line manually and manually specify a new --user-data-dir=c:\foo\bar profile location. (Point it to a new/empty directory and Chrome will populate it for you.)
Using this manually-launched browser, navigate to the page you need to interact with, activate the link, click the "always open" checkbox, and run the program once.
Next, close Chrome and save a copy of the entire new user profile directory. When you run your Selenium tests, make sure to always pass Chrome the same command line options pointing it to that user profile. These settings are now persisted, so the link will open without user intervention in the future. (This question may be of help to feed the right command line args to Chrome.)
For repeatable tests, you will probably want to save a static copy of this profile and redeploy it whenever you launch Selenium.
If you are using Javascript+Selenium or WebdriverJS then use this :
chromeOptions = {
'args': ['--test-type',
'--start-maximized',
'use-fake-ui-for-media-stream',],
'prefs': {
protocol_handler: {
excluded_schemes: {
'yourprotocolname': false
}
}
},
};

"Unknown command received" errors using MicrosoftWebDriver and Selenium (C#)

I am using Selenium (v2.47) and the Microsoft Web Driver (v10.0.10240.0). I am working with some existing C# code that already runs fine on Firefox, IE and Chrome and I want to use it to test the new Edge browser on Windows 10. My code is able to successfully open the browser and navigate to my login page. However I get an "Unknown command received" exception when I do a few basic things such as:
1) maximize the browser
2) call .FindElement(by) on an existing IWebElement.
For example:
driver.Manage().Window.Maximize(); //throws exception
...
IWebElement parent = driver.FindElement(By.TagName("body")); //works
...
parent.FindElement(by); //throws exception
Has anyone seen either of these work with Selenium and C# for the Edge browser? Maybe I am doing something wrong here. Or does "Unknown command received" just mean it is unimplemented functionality that will come in the future?
There was a fair amount of missing functionality in the initial (10.0.10240) Edge driver release, including missing support for IWebElement.FindElement(). Subsequent releases, which also required an update to Edge itself via Windows 10 updates, and until very recently only available via so-called Insider builds. A full accounting of what was implemented and when is provided by Microsoft at their WebDriver implementation status page.

How to detect when an internet-browser is open in Windows Forms and do an action if an URL was fired?

I want to write a program which recognizes when a browser is open and which do every time an action, when the user went to a website. For example:
The program is running as a system tray and starting automatically on windows startup. (this works)
Now the program runs an function, if the client open a random internet-browser (IE, Chrome, ...) which have the example-code MessageBox.Show("You opened a browser!").
If the user types for example "www.google.com" in the address bar and push [enter] the program should open an example-function like MessageBox.Show("You entered " + enteredURL) before the Website is loaded.
Thanks in advance for your help!
Take a look at the Navigating event:
Occurs before the WebBrowser control navigates to a new document.
It is possible to connect to an existing instance of IE, but you'll need to work with underlying the COM API (see here).
For other browsers there is no general mechanism: you'll need to work out if some API even exists browser by browser.

Prevent user from closing Firefox

I absolutely need a user to log out of a website which she/he uses to access our database. If one doesn't log out, and simply closes the browser, the system locks the username for an hour. I did not implement it, it's just the way it works.
I thought to write a simple C# program that would somehow detect whether the user logged out, and if not, prevent them from closing the browser.
1) Is there Firefox API, or any other way to read the website content in firefox.exe process?
2) When a user hits 'X' to close the browser, is it possible to abort the termination of firefox.exe process? (probably this is the deal-breaker question).
I would appreciate any hints. Thanks!
Every user should have a session, if you are using authentication. Sessions can be configured to expire. All you need to do is just to handle an appropriate session expire event.
Do not look for any hack to handle a browser exit event - it is a dangerous path:
Everybody would hate it, and there is no chance you can make it reliable, i.e. working in newer versions of browsers, supporting many browsers on different OS etc
This may work in Firefox Mozilla (sample), but may not work in IE or Chrome
Application can be killed by OS, so browser events will not get a chance to fire and your handling code will not work
You can't stop the user from closing firefox, because there a lot of ways it can be closed that can't be controlled by your code (e.g. killing the process from taskmon). However, you can detect the closure event in your code (window.onClose() event) and do the log out process.
However, in case of firefox (or any other browser for that matter), gets killed rather than being closed, window.onClose() will not work. So its better to handle the session in the server rather than depending on the client behavior.
What you can do is use javascript to detect the browser closing or leaving your site and in those instances fire a method or hit a webservice that logs them out. Very quick, very simple and will work across browsers.
You cannot prevent a user from closing a program with legitimate methods. This is for obvious security purposes.
I agree with oleksii. But you can make it less easy for users to close Firefox.
I'm currently writing an add-on (via the SDK) that listens to the "quit-application-requested" Observer Notification and sets aSubject.data to true preventing Firefox from quittng the application.
observe: function(aSubject, aTopic, aData) {
if (aTopic == "quit-application-requested") {
aSubject.QueryInterface(Ci.nsISupportsPRBool);
aSubject.data = (this.canQuit() == false);
}
}
But what I actually want is a certain window not being closed, as to not close the web application (a FileMaker database).
Therefore I've also tried disabling all commands, all keys and all menus (browser XUL), like so:
var allCommands = win.document.getElementsByTagName("command");
for (let i = 0; i < allCommands.length; i++) {
allCommands[i].setAttribute("disabled", "true");
}
var allKeys = win.document.getElementsByTagName("key");
for (let i = 0; i < allKeys.length; i++) {
allKeys[i].setAttribute("disabled", "true");
}
var allMenus = win.document.getElementsByTagName("menu");
for (let i = 0; i < allMenus.length; i++) {
allMenus[i].setAttribute("disabled", "true");
}
But users can still quit the application and thus close the window with the web application unless I prevent opening new Firefox windows.
So "it" works but I would like for them to still browse and just not close a specific tab or window in which the tab resides.
Without preventing opening of new windows it doesn't work because apparently when a user opens a new window then when users press Alt+F4 it would not be an application quit but a window close. Although I thought I had disabled all commands/keys/menus, still there exists some kind of close possibility.
Does anyone have any ideas on how to accomplish that without preventing the opening of new windows?

Categories

Resources