1

I have a web application (MVC4, KnockOut) which I'm trying to test using CodedUI. There is a form on one of the screens with a bunch of select tags, and a button which has a knockout binding calling a WebAPI when clicked. After the WebAPI call, the user is redirected to another screen.

When I use this screen manually I can select values, then click the button and the application functions as expected: WebAPI is called and if successful, there is a redirect.

However, when I use CodedUI to find and click the button, I will get a popup asking me if I'm sure I want to leave the page. I think this is default Internet Explorer behavior when leaving a page with form data. My question is, why does this happen with the CodedUI automation, but not when I manually click the button?

I'm using IE11 and VS2012 Premium Update 4. Here is a small snippet of my UI automation code:

var button = new HtmlButton {Container = BrowserWindow};
button.SearchProperties.Add(HtmlControl.PropertyNames.Title, "My button title");
Mouse.Click(button);

1 Answer 1

0

I managed to find out that in the function that calls the WebAPI using AJAX, we first disable the onbeforeunload event. Still, this does not seem to get called when CodedUI clicks the button. I've managed to work around this by using

BrowserWindow.ExecuteScript("window.onbeforeunload = null;");

However, I still can't figure out why I need to do this...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.