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>
這裏是什麼樣子:
我有這個代碼無框架的工作,但是當使用框架時,我找不到一種方法來點擊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();
}
}
是ID是錯字。但你的答案釘牢了謝謝:) – yantaq