如何在确认从框架(Watin)打开的弹出窗口中单击“确定”?
How to click OK in confirm popup opened from a frame (Watin)?
当它位于 iframe 中时,我找不到点击确认弹出窗口的方法。我可以找到 iframe 并单击 "Clicked OK" 按钮,然后弹出确认按钮,此时我被卡住了。我在下面发布了我的 html 和 C# 代码。
这里是文件:///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>
这里是 file:///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();
}
}
改变
iframe.Button("btnId").Click();
到
iframe.Button("myButton1").ClickNoWait();
按钮 id 可能只是您测试代码中的错字,重要的是将 Clinck 更改为 ClickNoWait。我刚刚测试过 - 它对我有用
当它位于 iframe 中时,我找不到点击确认弹出窗口的方法。我可以找到 iframe 并单击 "Clicked OK" 按钮,然后弹出确认按钮,此时我被卡住了。我在下面发布了我的 html 和 C# 代码。
这里是文件:///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>
这里是 file:///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();
}
}
改变
iframe.Button("btnId").Click();
到
iframe.Button("myButton1").ClickNoWait();
按钮 id 可能只是您测试代码中的错字,重要的是将 Clinck 更改为 ClickNoWait。我刚刚测试过 - 它对我有用