C # Coded UI testing - enter text into javascript window.prompt

I am running coded UI tests in Visual Studio Enterprise 2017.

My test web page has a javascript popup asking for an email address. I can find the confirmation Popup (selection is highlighted correctly) and I can click buttons on it like cancel.

confirmationPopup = new WinWindow();
confirmationPopup.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Dialog");
confirmationPopup.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "#32770");
confirmationPopup.TechnologyName = "MSAA";
confirmationPopup.Find();
confirmationPopup.DrawHighlight();

var cancelButton = new WinButton(confirmationPopup);
cancelButton.SearchProperties.Add(WinButton.PropertyNames.Name, "Cancel");
Mouse.Click(cancelButton);

      

What I'm trying my best to do is enter text into the popup input box:

var textInput = new WinEdit(confirmationPopup);
textInput.SearchProperties.Add(WinEdit.PropertyNames.ClassName, "Edit");
textInput.TechnologyName = "MSAA";
textInput.DrawHighlight();
textInput.Text = "bill@microsoft.com";

      

The selection is around the correct control, but the line textInput.Text = gives an error Additional info: SetProperty from "Text" is not supported by control type: Window

Any ideas what I am doing wrong?

+3


source to share


1 answer


Here is an example of interacting with the javascript tooltip window.

// go to a public site which has a prompt
var window = BrowserWindow.Launch("http://www.javascriptkit.com/javatutors/alert2.shtml");

var contentDiv = new HtmlDiv(window);
contentDiv.SearchProperties.Add(HtmlDiv.PropertyNames.Id, "contentcolumn", PropertyExpressionOperator.EqualTo);

var promptButton = new HtmlInputButton(contentDiv);
promptButton.SearchProperties.Add(HtmlInputButton.PropertyNames.ControlDefinition, "name=\"B4\"", PropertyExpressionOperator.Contains);

promptButton.SetFocus();
Keyboard.SendKeys("{ENTER}");

// now the prompt is showing, find it and set text
var promptWindow = new WinWindow();
promptWindow.SearchProperties.Add(WinWindow.PropertyNames.ControlType, "Dialog");
promptWindow.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "#32770");

promptWindow.DrawHighlight();

var middleWindow = new WinWindow(promptWindow);
middleWindow.DrawHighlight();

var inputBox = new WinEdit(middleWindow);
inputBox.DrawHighlight();
inputBox.Text = "Hello world!";

      



When using the check encoded ui function, I can see that there is a middle window. Using this or not, I can find the edit.

2 Windows

+1


source







All Articles