我正在尝试以编程方式单击“保存”按钮并测试窗口保存对话框是否出现:除了我认为的断言声明外,我还有其他所有内容。我不知道如何断言我的自定义SaveDialogBox对用户显示。
[test]
public void Method_WhenThePersonIsNotfound_ClickingTheButtonSavesLetterToWordDocument
{
//arrange
CreateNewPage(); //creates IE window enters fields and clicks submit on first page.
//act
this.InternetExplorerDriver.FindElementById("SaveForm").Click(); //Clicks my button that should produce a save dialog box.
//assert
//Assert statement to verify that when button was clicked the save dialog box to save the letter in word appears.
答案 0 :(得分:2)
我认为你不能:I can't interact with a popup dialog. My test stops in its tracks!。 “保存文件”被特别提及为无法与Selenium进行交互。
答案 1 :(得分:0)
使用异常来实现逻辑不是一个好习惯,但也许这个快速的解决方案可能有所帮助:
try {
this.InternetExplorerDriver.SwitchTo().Alert().Accept();//Appears sometime
}
catch (NoAlertPresentException)
{
// this code will perform if no alert is shown
}