Unable to handle authentication pop up - c#

I am using C# , Selenium , AutoIt and Google Chrome.
I can launch the browser, and can see the authentication pop up.
Pop up window disappears when below code is executed and after that the browser stays there forever.
autoItX3 autoIt = new AutoItX3();
Driver.Instance.Manage().Window.Maximize();
Driver.Instance.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(2);
try
{
Driver.Instance.Navigate().GoToUrl(Driver.BaseAddress);
}
catch
{
return;
}
autoIt.WinWait("Authentication Required");
autoIt.WinActivate("Authentication Required");
autoIt.Send("admin");
autoIt.Send("{TAB}");
autoIt.Send("pass");
autoIt.Send("{ENTER}");
Driver.Instance.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(-1);

You are trying to automate a child window.
Autoit doesn't see child windows untill told to.
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
Allows the window search routines to search child windows as well as
top-level windows. 0 = (default) Only search top-level windows 1 =
Search top-level and child windows

hard to make comment without knowing the internals of the authentication implementation on the server. One thing is sure - it is a bad idea from security view because parameters appended to the URL are not secure.
like : http://myURL.com/index.jsp/j_security_check?j_username=username&j_password=password
or
"http://username:password#www.example.com/")
this is what worked for me according to our internal authentication :
https://myURL.com/login/Login.aspx?usestandardlogin=1
so its => "http:YouURL.com" + "?" + "usestandardlogin=1"
now I am not seeing any pop up , it just re-direct me on login.

Related

Identify popup window Selenium in IE11 32 bit C#

I am having trouble identifying a popup to handle it. This is what I tried:
string dialog4;
string dialog5;
try
{
IAlert alert = driver.SwitchTo().Alert();
dialog4 = alert.Text;
alert.Accept();
dialog5 = "nothing alert";
}
catch (NoAlertPresentException f)
{
try
{
dialog4 = driver.SwitchTo().Frame(0).Title;// "dialog4";//
dialog5 = driver.SwitchTo().Frame(1).Title;// "dialog5";//
}
catch (NoSuchFrameException e)
{
try
{
dialog4 = driver.SwitchTo().Window("iHTKK").Title;
dialog5 = "nothing window";
}
catch
{
dialog4 = "nothing 4";
dialog5 = "nothing 5";
}
}
}
The code wait 10 seconds and the webdrive wait 30 seconds after clicking the red-highlighted button to make sure that the pop-up has time to be caught.
And the code return "nothing 4" and "nothing 5".
xPath doesn't work very well in this project, I don't know why but I tried with different elements before but xPath do not work.
I could not open F12 unless I response to this pop-up. I could open it before and after the existence of this pop-up.
I also tried to find
in the website (all HTML and .js files) for the information in the pop-up box using search function in Developer tool (F12) in Debugger and Dom Explorer tabs.
Nothing found. This is not my website.
I attached the screen-shot with Window spy (an utility comes with AutoHotkey help identify windows). The pop-up was created by a process call "jp2lancher.exe". My Java version is 8.x 32 bit if that's of concern. While it seem like the pop-up is from a different process, I can't interact with IE until I response to that pop-up. However, I can close it via "Close all windows" action in the task bar and the pop-up will still exist.
What else can I do to identify this pop-up?
After testing around, it's confirmed that Window Spy tool is a good way to identify if a pop-up is generated by the browser/driver. In ahk_exe line, it will say a window is run by which executable file. In my case, the pop-up is indeed a Java plug-in that is loaded from the website and run on my computer. I finally use AutoIt to handle that window. If anyone use AutoIt, keep in mind that it is a DIFFERENT language and all actions must be initiated in its format.

C# IE11 Automation - Cannot Connect To Open IE Window

I'm trying to connect to an Internet Explorer window that is already open. Once connected I need to send some keystrokes (via SendKeys) to the IE window for some processing. I've got the following code below that works up until the SendKeys command. It finds the IE window titled "Graphics Database". When it hits "SendKeys.Send("{TAB}");" I get the error "An unhandled exception of type 'System.NullReferenceException' occurred".
Additional information: I also get the following on the NullReferenceException error. The weird thing is if I code to open a new IE window and then use SendKeys it works fine. Connecting to an existing windows seems to cause this issue.
SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method.
Can anyone please help me figure out what to do to fix this?
Andy
InternetExplorer IE = null;
// Get all browser objects
ShellWindows allBrowsers = new ShellWindows();
if (allBrowsers.Count == 0)
{
throw new Exception("Cannot find IE");
}
// Attach to IE program process
foreach (InternetExplorer browser in allBrowsers)
{
if (browser.LocationName == "Graphics Database")
{
MessageBox.Show ("Found IE browser '" + browser.LocationName + "'");
IE = (InternetExplorer)browser;
}
}
IE.Visible = true;
System.Threading.Thread.Sleep(2000);
SendKeys.Send("{TAB}");
SendKeys.Send("G1007");
SendKeys.Send("{ENTER}");
I was able to resolve this issue. I could never get the IE.Visible = true to work. This seemed to do nothing in my code. I had to use the SetForegroundWindow() to set the focus to the IE window.
// Find the IE window
int hWnd = FindWindow(null, "Graphics Database - Internet Explorer");
if (hWnd > 0) // The IE window was found.
{
// Bring the IE window to the front.
SetForegroundWindow(hWnd);
This site helped me immensely with getting the SetForegroundWindow() working.
http://forums.codeguru.com/showthread.php?460402-C-General-How-do-I-activate-an-external-Window
Andy please bear with me as this will be long. First you are going to want to look mshtml documentation and Dom. https://msdn.microsoft.com/en-us/library/aa741314(v=vs.85).aspx I don't know why automation is so convoluted but it is. The UIautomation class works great for windows apps but has nothing really for IE that I've been able to find. Others will point to third parties like waitn and selenium. Waitn appears to no longer be supported and selenium won't let you grab an open IE browser. I have gone down this path recently because I wanted to be able to create an app to store my web passwords and auto fill them in since I can't save my username and passwords in browser due to security restrictions. I have an example here and hope it helps. First open up IE and navigate to http://aavtrain.com/index.asp. Then have a console project with mshtml referenced and shdocvw. Here is code below. It gets the window then finds elements for username, password, and submit. then populates the username and password and clicks the submit button. I don't have a login to this site so it won't log you in. I have been using it for my testing. Problem I have is sites with javascript login forms. If you get further with this info please post back as I am still trying to evolve the concepts and create something reusable.
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
Console.WriteLine("Starting Search\n\n\n");
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
if (ie.LocationURL.Contains("aavtrain"))
{
Console.WriteLine(ie.LocationURL);
Console.WriteLine("\n\n\n\n");
Console.WriteLine("FOUND!\n");
mshtml.HTMLDocument document = ie.Document;
mshtml.IHTMLElementCollection elCol = document.getElementsByName("user_name");
mshtml.IHTMLElementCollection elCol2 = document.getElementsByName("password");
mshtml.IHTMLElementCollection elCol3 = document.getElementsByName("Submit");
Console.WriteLine("AutofillPassword");
foreach (mshtml.IHTMLInputElement i in elCol)
{
i.defaultValue = "John";
}
foreach (mshtml.IHTMLInputElement i in elCol2)
{
i.defaultValue = "Password";
}
Console.WriteLine("Will Click Button in 2 seconds");
Thread.Sleep(2000);
foreach (mshtml.HTMLInputButtonElement i in elCol3)
{
i.click();
}
}
}
Console.WriteLine("Finished");

WatiN doesn't find anything

I'm new to C# and I'm trying to do an application that automatize Internet Explorer.
When I click a button, the application does :
using ( var Browser = new IE())
{
Browser.GoTo("http://testweb.com");
Browser.TextField(Find.ByName("username")).TypeText("User");
Browser.TextField(Find.ByName("password")).TypeText("Pass");
}
But it doesn't write anything. It navigates to the web but...
Try this:
IE ie = null;
ie = new IE();
ie.GoTo("Link");
ie.WaitForComplete();
At least to get started.
For the other bit, you need to get an exact identification and then you can tell WaTiN to interact with it.
Textfield userTextBox = ie.Textfield(Find.ByName("name"));
userTextBox.TypeText("user");
This may seem banal but now you can add a peek definition in your code and see if "userTextBox" gets found by name. If it doesn't you need to find it through another method (ID or class).

How to enable/allow java to run in a CefSharp application

We are making a web browser to experiment with Oracle's ADT/Forms technology. All it needs to do is go to the web address and run the Java applet.
I'm using (trying to, at least) CefSharp3 (fresh clone from https://github.com/cefsharp/CefSharp).
I created a WPF project for this, got it working (I can navigate to Google, here, Oracle, etc) however, when I navigate to our Java applet I seem to get nothing but a blank screen.
I have set browser-attributes
"JavaDisabled"
"PluginsDisabled"
"WebSecurityDisabled"
(grasping at straws there!) appropriately and still I only see a blank screen.
I'm wondering if maybe the app does not have permissions to the JRE? Maybe the JRE needs to be included in the project?
This is the result of the Debug file (after a fresh run that ONLY goes to the Java applet)
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121439:ERROR:renderer_main.cc(226)] Running without renderer sandbox
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:resource_bundle.cc(280)] locale_file_path.empty()
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
[1011/121441:WARNING:content_browser_client.cc(480)] No browser info matching view process id 3 and routing id 2
The Java applet works no problem in Firefox, Chrome, IE, and Chromium (with WinForms). It could just be that WPF and Java don't jive.
Here's some code! -- it's not much, but it doesn't take much to use this framework -- I AM quite impressed.
public partial class MainWindow : Window
{
public MainWindow() {
InitializeCef();
InitializeComponent();
SetBrowserSettings();
((IWebBrowser)webBrowser).Load("URL_To_Java_Applet");
}
private void InitializeCef() {
var settings = new CefSharp.CefSettings()
{
PackLoadingDisabled = true
};
settings.IgnoreCertificateErrors = true; // could be preventing the JRE?
Cef.Initialize(settings);
}
private void SetBrowserSettings() {
BrowserSettings settings = new BrowserSettings();
settings.JavaDisabled = false;
settings.PluginsDisabled = false;
settings.WebSecurityDisabled = true; // desperate attempt to allow JRE to run!
webBrowser.BrowserSettings = settings;
}
}
Looks like you're right...
It could just be that WPF and Java don't jive.
Try with WinForms, not WPF where prospects doesn't look good (note WPF run in OSR mode)
See this CEF forum thread
update: I tried with http://java.com/en/download/installed8.jsp and Win32 builds of CefSharp.Winforms|Wpf.Example - they both work as expected with JRE 7.67 x86. Of course the x64 Examples didn't work as I don't have a x64 JRE on my PC.

Why is Process.MainWindowTitle always empty for all but one window?

When accessing Process.MainWindowTitle as follows...
Process[] processes = Process.GetProcessesByName( "iexplore" );
...and then loop over the resulting array, I always end up with the MainWindowTitle being empty for all but one item in the array. In my case I've got two Internet Explorer windows open, one with a single tab and one with two tabs in it.
Running my code I always get the MainWindowTitle for the window and tab that I had last active - all the others remain empty. The strange thing is that the process ID in which the MainWindowTitle is filled is always the same - if I activate the other IE window or tab before running my code, the process ID is always the same:
if ( !processes.Any() )
{
MessageBox.Show( "TODO - No matching process found" );
return;
}
if ( processes.Count() > 1 )
{
foreach ( Process currentProcess in processes )
{
// More than one matching process found
checkedListBox1.Items.Add( currentProcess.Id + " - " + currentProcess.MainWindowTitle + " - " + currentProcess.ProcessName );
}
return;
}
Output could therefore be for the first run like:
4824 - - iexplore
3208 - - iexplore
4864 - Google - Windows Internet Explorer - iexplore
Next run (with the other IE window selected beforehand):
4824 - - iexplore
3208 - - iexplore
4864 - id Software - Windows Internet Explorer - iexplore
I've read about this post, but I didn't get any further with my problem (and it seems to go into a somewhat different direction anyway).
Why do I always only get one non-empty MainWindowTitle?
Remember that internet explorer uses a hosting model - one iexplore.exe instance hosts the internet explorer frame, the other iexplore.exe instances just display the contents of tabs.
The only IE instance with a top level window is the iexplore.exe process which hosts the frame.
This article discusses the multi-process architecture of various web browsers. As I understand it, browsers are moving to a multi-process model - that way a failure in one web page won't affect other pages. This article goes into more detail about IE's multi-process model.
One option to make this happen reliabely (see comments above) is to implement a BHO - esp. the DWebBrowserEvents2::WindowStateChanged Event is usefull in this scenario.
BHOs are implementations of a bunch of COM interfaces and get loaded into the browser process/each tab... best way to implement them is in C++ IMO.
But it is certainly possible to do so in .NET (although not recommended):
http://www.codeproject.com/Articles/350432/BHO-Development-using-managed-code
http://www.codeguru.com/csharp/.net/net_general/comcom/article.php/c19613/Build-a-Managed-BHO-and-Plug-into-the-Browser.htm
AddIn-Express for IE (commercial library for .NET-based BHOs)
I had the same problem. With Teamviewer Host, we have the QuickConnect Button on some Application. In my case WinWord. If you remove or disable the QuickConnect, the MainWindowTitle will be enhanced

Categories