2017-08-07 26 views
3

我在Visual Studio企業運行編碼的UI測試2017C#編碼的UI測試 - 文本輸入到一個javascript window.prompt文本框

我測試的網頁有一個JavaScript彈出詢問的電子郵件地址被輸入。我可以找到confirmationPopup(突出顯示正確繪製),並且我可以單擊其中的按鈕,例如取消。

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); 

我所努力做的就是在彈出的輸入框中輸入文本:

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

的亮點是圍繞正確的控制繪製,但textInput.Text =行給出了一個錯誤 附加信息:控件類型不支持「文本」的SetProperty:窗口

任何想法我做錯了什麼?

+0

您確定您發佈的代碼是正在運行的代碼嗎?該錯誤表明控件類型錯誤。您不需要爲類名稱添加搜索屬性,它將成爲WinEdit定義的一部分。您不應該需要指定TechnologyName。在DrawHighlight調用中,突出顯示文本區域還是整個確認彈出窗口? – MPavlak

+0

我是新來的,所以是的,這是代碼運行,但我完全接受它可能既不是好也不是必要的代碼。 drawhighlight就在文本區域周圍。如果我確認confirmationPopup.DrawHighlight(),那麼包圍整個確認彈出窗口。 – gregm

回答

1

這裏是一個與javascript提示窗口交互的例子。

// 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!"; 

當使用編碼的UI的檢查功能時,我看到有一箇中間窗口。使用它或不使用,我能夠找到編輯。

2 Windows

+0

互動,有一個'中間窗口'。我會嘗試這種方法並回報。 - 謝謝 – gregm

+0

解決了,謝謝。問題是有一個'隱藏'(又名看起來不夠硬),窗口內的窗口和文本輸入是在 – gregm

相關問題