Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm running coded UI tests in Visual Studio Enterprise 2017.

My webpage under test has a javascript popup asking for an e-mail address to be entered. I can locate the confirmationPopup (highlight is drawn correctly), and I can click buttons within it, such as the 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 am struggling to do is enter text in the popup's input box:

var textInput = new WinEdit(confirmationPopup);
textInput.SearchProperties.Add(WinEdit.PropertyNames.ClassName, "Edit");
textInput.TechnologyName = "MSAA";
textInput.DrawHighlight();
textInput.Text = "[email protected]";

The highlight is drawn around the correct control, but the textInput.Text= line gives an error Additional information: SetProperty of "Text" is not supported on control type: Window

Any ideas what I'm doing wrong?

like image 828
gregm Avatar asked Jun 25 '26 22:06

gregm


1 Answers

Here is an example of interacting with javascript prompt 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 inspect feature of coded ui, I see there is a middle window. Using it or not, I am able to find the edit.

2 Windows

like image 111
MPavlak Avatar answered Jun 27 '26 12:06

MPavlak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!