Watin : Open Windows form in watin - c#

i have a link that when we click will produce a windows form that prompt us to download.Is there a way using watin for us to attach to this form and click the button?Can someone please direct me to the correct way?

What do you mean by saying, that clicking a linkd produces a windows form? Isn't it just a separate IE window, probably created by js window.open? If so, then you need to create separate WatiN IE instance by attaching to that window. For example, if you want to control internet explorer window with title "My popup", you can do it that way:
var popup = IE.AttachTo<IE>(Find.ByTitle("My popup"))
You can find IE windows using constraints created using: Find.ByUrl, Find.ByUri, Find.By("hwnd", windowHandle) and mentioned Find.ByTitle.

Related

Find and Close a Dialog in Firefox using Selenium and C#

Issue: My selenium script is not recognizing and closing a dialog box that pops up when I redirect to a URl that contains file to download. The attached image shows the dialog I am referring to.
I know this has been asked a million times and I have spent at least 24 hours researching and trying other suggestions posted across the web but with no success. I am hoping the attached image will clarify which Firefox dialog box I am referring too.
I have tried the following solutions
1. Creating IAlerts (Alert element is not found)
2. Searching by trying to find the element by xpath (xpath to cancel was not found)
3. WindowsHandler Method (was not able to figure out the window name)
Any help on this would be greatly appreciated. Thank You in advance!
FireFox Dialog
There are several types of "popups".
Javascript dialogs - These are NOT HTML dialogs but are instead Javascript created dialogs. These consist of alert(), confirm(), and prompt() and can be handled with Alert.
HTML dialogs - These take on various forms depending on how they are formatted. If you right-click on the dialog and see the typical context menu for your browser, then it's an HTML dialog. They are part of the DOM of the current page so you can use Selenium to access this just as you would any other page (e.g., no window handles needed).
Browser window - These are actually another browser window that pops up and may look like a dialog, depending on how it's formatted. It's different than an HTML dialog because it can be moved outside of the current browser page frame. You will need to use window handles to access these windows as you would another tab in the browser. Once you get ahold of the window handle, you can access the HTML of the page like any other page.
Browser dialog - these take on various forms but are akin to System dialogs. They are not made up of HTML so they cannot be accessed by Selenium. Other than using a library to access them, you can interact with them in a limited fashion by sending keys such as <SPACE>, <TAB>, <ENTER>, etc.
What you have pictured is a (4) browser dialog. They it takes on different forms depending on the browser you do the action on. Your best course of action is probably send keys. Sometimes, depending on the browser, you can specify settings to autodownload a file to a specific location so that the dialog doesn't come up. I've never used this so I can't direct you there.
I was able to find and close a download dialog box by checking the amount of open windows after the dialog appears. This solution worked for me.
Find a link to open a dialog and click it:
var link = MyBrowser.Driver.FindElement(OpenQA.Selenium.By.Id("Button"));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].click();", link);
Get the new window count after the dialog opens:
var newWindowCount = MyBrowser.Driver.WindowHandles.Count;
Switch to the newly opened dialog and close it:
MyBrowser.Driver.SwitchTo().Window(MyBrowser.Driver.WindowHandles[newWindowCount-1]);
MyBrowser.Driver.Close();

Get CefSharp Browser Popup Window from parent form

I am using ChromiumWebBrowser(CefSharp) to load a website, When i click any link in the website, it open new popup window
I want to access ChromiumWebBrowser on new popup window but i do not know how do i can access it ?. Please can you them me
Thanks All
The latest version 43.0.0 now exposes a wrapper around the underlying CefBrowser (IBrowser), which allows you to perform browser related tasks (you can also get hold of the HWND for the created window if required).
Try implementing ILifeSpanHandler.OnAfterCreated, check the IBrowser.IsPopup property.
https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp/ILifeSpanHandler.cs#L48

How to open a seperate child window on a click to parent window silverlight?

I am new to c# and i create a project in silverlight-5 and i chose "ASP.NET web application" while selecting the project. which has GUI coding in xml and behind i code in c# to handle the events. The project on running opens Internet explorer and shows the GUI there.(It is to explain you what kind a project i have created, I am not using WPF application, there are lot of samples for WPF but less for silverlight using xml).
I have to create a GUI which will consists of a button intially (suppose "File" ). On clicking "file" it must shows 3 buttons."Browse","save","close". GUI must be like this http://prntscr.com/35qlf3 (Like on click to "file" there are is a window that opened so the same way it must open a window containing these 3 buttons and then on clicking these 3 buttons must open another window where i have some text boxes and buttons).
Whereas on further click to "Browse" will open a window on same Internet explorer(don't open new IE window) where i will have a button to "Browse" a file and will further browse the file on click to it (I already have the code for browsing but have no idea to create an interface of Parent-Child buttons like this).
And there simiral kind of functioning associated with all other 2 buttons clicks as well(I mean they will also open a window on their click in the same place and on the same Internet explorer window).
Any ideas how to achieve it ?
Any link or piece of code is most appreciated.
Make use of child Windows in Silverlight.This how you open child window from Main Page in Silverlight,
var ChildWindow1 = new ChildWindow();
ChildWindow1.Show();

How to prevent Silverlight Webbrowser Control to open links in new windows?

I have a Silverlight 5 application which shows a Dynamics CRM 2013 webpage (list of accounts) in a Silverlight webbrowser control. When the user clicks on one entity record in the list the detail view of that record should open in the same browser. It is opened in a new browser window instead. How can I make the Silverlight webbrowser open it in the same window? In a standard Internet Explorer it is opened in the same browser window.
I found a solution how to achieve that in a .Net webbrowser control. However this is different from the Silverlight webbrowser control I have. Especially the "Document" property and the events "DocumentCompleted" and "NewWindow" are missing.
I use Internet Explorer 11 on a Windows 7 machine to test it. Any hint is highly appreciated.
Cheers,
Arne
Try this:
HtmlPage.Window.Navigate(new Uri("the address here"), "_self");
The key is the second parameter "_self", which means that you want to open the link on the same page. You can also use "_blank" for new tab or "_top" to put it on top of the hierarchy.
Useful links
http://msdn.microsoft.com/en-us/library/cc189809(v=vs.95).aspx
http://www.w3schools.com/jsref/met_win_open.asp
Hope it helps

Not able to open second page of my wpf browser application in a new browser window?

I am new to wpf.I am doing a browser application in wpf and i wanted to know if i can open my second page in a new browser window.
I am able to open a new browser window using system windows diagnostics.process statement and i am able to load my project also but not the desired page in it.
I am also able to open my desired page like a aplication using uri.
But what i want is a hybrid of both and i am not able to find anything to suit my purpose.
Thanks in advance mates
you can use this code
1. Add a new window NewWindow
2. var newWindow= new NewWindow();
newWindow.Show(); // works
//Or use ShowDialog, if parant wait close of child window
newWindow.ShowDialog();

Categories