Issue with WatiN and IE9 regarding multiple dialogs - c#

I am using the latest 4/12/2011 build of WatiN (2.1.0.1196).
I have an aspx page loaded into an IFrame in Dynamics Crm. There is a button on the page that opens and modal dialog form. So far most of the test cases are working correctly with WatiN except for a specific use case.
If a specific combination of controls are set on the modal dialog, a confirm dialog box will pop up after the user presses the submit button. If the user selects ok it will continue the submit execution, if cancel it will return back to the modal dialog. The test times out when this confirm dialog box appears. I cant seem to get the handler setup right to catch the confirm dialog.
Here is a test method I have been trying:
[TestMethod]
public void Add_New_Post_To_Record_Public_NotOnBehalf_NoSub_No_Notifications()
{
using (var browser = new IE("URL to the IFRAME"))
{
var approveConfirmDialog = ReturnDialogHandler.CreateInstance();
var confirmCode = Guid.NewGuid();
//logon to CRM
logonToADFS(browser);
var recordPage = browser.Page<DiscussionRecordpage>();
recordPage.CreateNewPostButton.ClickNoWait();
HtmlDialog dialog = browser.HtmlDialog(Find.ByTitle("New Post"));
var messageText = dialog.TextField(Find.ByClass("required"));
messageText.TypeText("Type some text. Confirmation code: " + confirmCode.ToString());
var button = dialog.Button(Find.ByClass("submit-button"));
using (new UseDialogOnce(browser.DialogWatcher, approveConfirmDialog))
{
button.ClickNoWait();
approveConfirmDialog.WaitUntilExists();
approveConfirmDialog.OKButton.Click();
}
browser.WaitForComplete();
Assert.IsTrue(browser.ContainsText(confirmCode.ToString()));
}
}
I have tried a couple different variations all with the same result. I assume that I need to use the ReturnDialogHanlder.CreateInstance() method for IE9 compatibility, but the standard ConfirmDialogHandler did not seem to work either. Honestly, I don’t know if I am using the dialog handler correctly in this case, but I can click the ok buttons on other confirm dialogs that spawn from buttons on other pages. This is a bit unique since it is spawning from a modal dialog instead of a page.
I also tried using this custom handler (C# WatiN - Add an AlertDialogHandler to click ok button on every Alert dialog window) with no results.
Thanks in advance.

It's too hard. I suggest a workaround: most of the case, you could close the dialog using keyboard. so you could sendkeys to close the dialog. Just FYI.

Related

How i can set the Searchbar Inative and User click on this for open a Dialog

My Question is how can i Build in Android C# an SreachView this is off by but Show and any User click on this a Dialog open and asked the User to give her ok.
I work in a Fragment
SearchView searchView;
searchView = (SearchView)View.FindViewById(Resource.Id.MenuSearchitem);
searchView.ClearFocus();
searchView.SetOnQueryTextListener(this);
searchView.SetOnQueryTextFocusChangeListener(this);
searchView.SetIconifiedByDefault(false);
searchView.SubmitButtonEnabled = true;
searchView.QueryHint = mapViewModel.AddressPlaceholder;
thats all fine, but nothing work for click on the searchbar and no dialog is open.
follow ways i have used IOnFocusChangeListener and IOnSuggestionListener dont gave the right way for me
you can use onTouchListner, wherever you will touch on the screen the touch event will be triggered, there you can check which widget is clicked just check it and open dialog in it.

C# ChromiumWebBrowser: Prevent control from stealing focus

I'm making a program that has a Form with a ChromiumWebBrowser in it. The navigation is done automatically. When webbrowser complete it's task, I'll dispose it, create a new webbrowser, add it to form, and load a new address.
But, when the new webbrowser was created and added to form, the program jumps in front of what ever other program is in the top with focus. Example: I start my program, press the button to start its task, open notepad to type some text and my program jumps in front of it when navigating to a new site.
Even when the window is minimized, it still steals focus from other open programs.
How do I prevent it stealing focus after it is created?
As #amaitland said, this looks like a bug.
Workarounds I've used are:
1) disable the browser. This will prevent the browser from receiving mouse/keyboard input, but it won't "grey-out" the control.
Browser1 = New CefSharp.WinForms.ChromiumWebBrowser(url)
Browser1.Enabled = False
2) Pass a callback .net function for when the page loads where you simply put the focus back to winforms by focusing on a label of your choice.
Label1.Focus()
Your Form need set: this.Topmost = false;
AND just set: this.BringToFront();
Add new browser to the form just like the function as follow:
private ChromiumWebBrowser AddNewBrowser(FATabStripItem tabStrip, String url)
{
if (url == "")
{
url = OpenUrl;
txtUrl.Select();
txtUrl.Focus();
}
else
{
tabStrip.Select();
tabStrip.Focus();
}
// ...
}
Hope has help to you. Thanks !

Use WatiN in windows Form to Automate Clicking and Writing in Internet Explorer C#

Internet Explorer is open and it is showing a webpage. We know there a drop down and a textbox and a button are exist in this page.
I need to select an item from drop down, writing a text in textBox and clicking on that button.
How Can I do these using WatiN by pressing on a button in windows form, I currently add its related libraries and I have add WatiN.Core in using section, but it seems it is not working with windows forms.
This is a very small example but not sure what you mean by "not working" (does it throw an exception, are you able to start the program, when you click the button it fails, you need to be more precise on this).
using(var ie = new IE){
ie.GoTo("http://www.yourwebpage.com");
TextField entry = ie.TextField(Find.ById("myEntryBox"));
Button btn = ie.Button(Find.ById("submit"));
SelectList menu = ie.SelectList(Find.ById("selectList"));
entry.Value ="Hello world");
menu.SelectByValue("2");
btn.Click();
}
if you are having other problems, please, let us know.

Handle a popup in selenium webdriver using c#

When I click on a button on a page, a popup is displayed. This is not a windows popup. It is the application popup.. The popup I get in my application is similar to the one i have shown in the image with a X button. now How do I move the driver control to the popup and then click on the close button available on the popup and then move back my control back to the original page..
I have to do this using Selenium WebDriver and C#.
You need to do the following...
Loop through the windows and find the desired window
Switch to the windows
Find the button in the current window and click the same
Here is the sample code in C#
foreach (string handle in browser.WindowHandles)
{
IWebDriver popup = driver.SwitchTo().Window(handle);
if (popup.Title.Contains("popup title"))
{
break;
}
}
IWebElement closeButton = driver.FindElement(By.Id("closeButton"));
closeButton.Click();
The new pop message too have an id or class name..
First get the class name or id of that pop up and the go for the xpath(may be we will find class name) of the close button and click on it.
The example you have shown is not a popup, but a simple DHTML window.
To access the X of the example you have provided, you could use: driver.findElementBy(By.id("profile-tooltip-closebtn")).click().
You can try
driver.switchTo().frame(0);

WatiN testing of a popup

I have an application that brings up a popup window when you click a link. I have a watin test that naviates to the page and clicks a link to open the popup. This is my current code:
[Test]
public void TestCommentBoxInput()
{
window.GoTo("mylocalurl");
window.Link(Find.ById("popuplink.aspx")).Click();
IE iepopup_1 = IE.AttachTo<IE>(Find.ByUrl("popuplinkurl.aspx"));
iepopup_1.TextField(Find.ById("txtComments")).TypeText("Commenttest");
}
As you can see I tried attatching the popup window to the created browser called window. When I run my test it just stops at the popup window and never enters text in the box. How do I go about making my program regonize that it is now to be operating on the popup and not the original window?
EDIT: I am dealing with a Modal Dialog.
I think the Find.ByUrl try to do a exact match, try with a Find.ByUrl(u => u.Contains("popuplinkurl.aspx"))
So I have figured out the problem, the problem was I was using a Modal dialog and they are handled differently. My new code is as follows in case anyone is stuck in the same position I was in. :)
public void TestCommentBox()
{
window.GoTo("mylocalurl");
window.Link(Find.ById("popuplink.aspx")).ClickNoWait();
HtmlDialog dialog = window.HtmlDialog(Find.ByTitle("TestPopup"));
dialog.TextField(Find.ById("Txtcomments")).TypeText("Commmenttest!");
}
The important lines are:
window.Link(Find.ById("popuplink.aspx")).ClickNoWait();
Notice that I am using ClickNoWait() and not just Click, I am unsure as to why this makes the difference, but it does! If someone could explain that that would be great.
HtmlDialog dialog = window.HtmlDialog(Find.ByTitle("TestPopup"));
Because I am dealing with a Modal dialog you have to declare a new HtmlDialog. Also in order to use Html dialog make sure you include Watin.Core.DialogHandlers. I hope this is helpful to someone out there! :)

Categories