Watin對(duì)Web頁(yè)面彈出窗口,對(duì)話框,提示框的處理
處理彈出窗口
首先創(chuàng)建一個(gè)web頁(yè),用于演示彈出窗口。
<inputid="Button1"type="button"value="button"onclick="openwindow()"/>
<scripttype="text/javascript">
functionopenwindow()
{
window.open("http://localhost/Test/test2.htm");
}
</script>
上述代碼,點(diǎn)擊“Button1”后,彈出窗口test2.htm.我們要做的是如何處理test2.htm頁(yè)面
Watin處理代碼如下:
IEie =newIE("http://localhost/Test/");
//點(diǎn)擊按鈕,打開新窗口test2
ie.Button(Find.ById("Button1")).Click();
//查找新窗口test2并賦給新的IE對(duì)象
IEnewie =IE.AttachTo<IE>(Find.ByTitle("test2"));
//使用新的IE對(duì)象可以繼續(xù)對(duì)新窗口進(jìn)行操作了
newie.TextField(Find.ById("Text1")).TypeText("this is new ie");
處理confirm彈出框
首先創(chuàng)建一個(gè)web頁(yè),用于演示confirm對(duì)話框。
<inputid="myButton1"type="button"value="this is a button"
onclick="confirmMe(); return false;"><br>
<script>
functionconfirmMe() {
varanswer = confirm ("Are you having fun?")
if(answer)
document.getElementById("myButton1").value="Clicked OK";
else
document.getElementById("myButton1").value="Clicked Cancel";
}
</script>