2015-11-06 34 views
1

我无法找到一种方法,当它位于iframe内时,点击确认弹出窗口。我可以找到iframe并单击“单击确定”按钮,然后确认按钮弹出,此时我卡住了。我在下面发布了我的html和c#代码。如何在确认从框架(Watin)打开的弹出框中单击确定?

以下是文件:///C/Temp/IFrame.html

<html> 
    <body> 
     <iframe id="FrameID" src="file:///C:/Temp/confirm1.html" width="100%" height="100%"> 
      <p>Your browser does not support iframes.</p> 
     </iframe> 
    </body> 
</html> 

这里是文件:/// C:/Temp/confirm1.html

<html> 
    <body> 
    <input id="myButton1" type="button" value="this is a button" 
     onclick="confirmMe(); return false;"><br> 
    <script> 
     function confirmMe() { 
     var answer = confirm ("Are you having fun?") 
     if (answer) 
      document.getElementById("myButton1").value="Clicked OK"; 
     else 
      document.getElementById("myButton1").value="Clicked Cancel"; 
     } 
    </script> 
    </body> 
</html> 

这里是什么样子:

enter image description here

我有这个代码无框架的工作,但是当使用框架时,我找不到一种方法来点击iframe中的确认对话框。

public static void ConfirmPopupFromFrame() 
{ 
    IE ie = new IE(); 
    ie.GoTo("file:///C:/Temp/IFrame.html"); 
    ie.WaitForComplete(); 

    Frame iframe; 
    try{ 
     iframe = ie.Frame("FrameID"); 
    } 
    catch (FrameNotFoundException ex){ 
     throw ex; 
    } 

    ConfirmDialogHandler confirm = new ConfirmDialogHandler(); 
    using (new UseDialogOnce(ie.DialogWatcher, confirm)) 
    {  
     iframe.Button("myButton1").Click(); // At this point confirm dialog pops up but below lines doesn't work since this is frame instance not ie. is there a way to make it work? 
     confirm.WaitUntilExists(); 
     confirm.OKButton.Click(); 
    }  
} 

回答

2

变化

iframe.Button("btnId").Click(); 

iframe.Button("myButton1").ClickNoWait(); 

按钮ID可能只是在你的测试代码一个错字,最重要的是改变Clinck到ClickNoWait。我刚刚测试过 - 它适用于我

+0

是ID是错字。但你的答案钉牢了谢谢:) – yantaq

相关问题