zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    android ImageSwitcher
    andriod Spinner
    andriod RadioButton
    anriod TabHost
    给大学生的几条良心建议
    6月最新地铁站周边二手房价格出炉
    机器学习 101 Mahout 简介 建立一个推荐引擎 使用 Mahout 实现集群 使用 Mahout 实现内容分类 结束语 下载资源
    Vim设置colorscheme小技巧
    2017年阳光私募基金一季度报告
    实用的 atom 插件
  • 原文地址:https://www.cnblogs.com/jenniferhuang/p/3421882.html
Copyright © 2011-2022 走看看