selenium IDE处理各种窗口问题解决方法

一、处理模态窗口:showModalDialog

由于弹出模态窗口后,就无法定位到当前窗口的元素和模态窗口的元素,需要添加js解决

模态窗口动作类似下面语句:

 

<input id="ctl00_CPH_TopAddButton" class="LongOrangeButtonStyle" type="button" value="Add Single Location" onclick="javascript:window.showModalDialog('EditLocation.aspx?EditOrAdd=Add',window,'dialogWidth:450px;dialogHeight:600px;status:no; directories:yes;scrollbars:no;Resizable=no;status:no');RefreshLocation();" name="ctl00$CPH$TopAddButton">

 此时,在生成模态窗口前, 先执行语句:

storeEval  if(selenium.browserbot.getCurrentWindow().showModalDialog){selenium.browserbot.getCurrentWindow().showModalDialog = function(sURL,vArguments,sFeatures){selenium.browserbot.getCurrentWindow().open(sURL, 'modal', sFeatures);};}  xx

 再点击

click 

id=ctl00_CPH_TopAddButton

   

 

 

则会以新页面形式弹出,就不会定位不到元素

 

操作完新页面后,执行下面2个语句,回到主窗口。

close    
selectWindow null  

 

 

 

二、处理confirm/alert/prompts弹出窗口

 处理方式如下:

相应示例代码如下:

<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>主窗口</title>
  <script type="text/javascript">
    function output(resultText){
      document.getElementById('output').childNodes[0].nodeValue=resultText;
    }

    function show_confirm(){
      var confirmation=confirm("Choose an option.");
      if (confirmation==true){
        output("Confirmed.");
      }
      else{
        output("Rejected!");
      }
    }

    function show_alert(){
      alert("I'm blocking!");
      output("Alert is gone.");
    }
    function show_prompt(){
      var response = prompt("What's the best web QA tool?","Selenium");
      output(response);
    }
   </script>
</head>
<body>

  <input type="button" id="btnConfirm" onclick="show_confirm()" value="Show confirm box" /></br>
  <input type="button" id="btnAlert" onclick="show_alert()" value="Show alert" /></br>
  <input type="button" id="btnPrompt" onclick="show_prompt()" value="Show prompt" /> </br>
  <br />
  <span id="output">
  </span>
</body>
</html>

 

 

 

 

 

 

posted @ 2013-12-04 14:29  jenniferhuang  阅读(4928)  评论(0编辑  收藏  举报