C# 使用Selenium如何测试屏幕上是否显示了保存对话框?

C# 使用Selenium如何测试屏幕上是否显示了保存对话框?,c#,selenium,C#,Selenium,我试图通过编程方式单击“保存”按钮并测试windows保存对话框是否出现:除了我相信的assert语句之外,我什么都有。我不知道如何断言用户会看到我的自定义SaveDialogBox [test] public void Method_WhenThePersonIsNotfound_ClickingTheButtonSavesLetterToWordDocument { //arrange CreateNewPage(); //creates IE window enters

我试图通过编程方式单击“保存”按钮并测试windows保存对话框是否出现:除了我相信的assert语句之外,我什么都有。我不知道如何断言用户会看到我的自定义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.

我不相信你能。Selenium特别提到“保存文件”无法与之交互。

使用异常实现逻辑不是一个好做法,但这种快速解决方案可能有助于:

try { 
      this.InternetExplorerDriver.SwitchTo().Alert().Accept();//Appears sometime
    } 
catch (NoAlertPresentException) 
    { 
      // this code will perform if no alert is shown
    }

你也可以看到答案所以这是一个网络集成测试?你所说的与NUnit关系不大,与你使用的框架有很大关系:Selenium、WatIN等。好的,我可以重新表述这个问题,很抱歉在这里讨论同样的问题:,有一个可能的解决方法。我认为这可能行得通,但在我的单元测试中,我需要断言一些东西。我应该断言.isFalse(this.InternetExplorerDriver.SwitchTo().Alert().Accept());