首页 技术 正文
技术 2022年11月15日
0 收藏 471 点赞 3,303 浏览 1674 个字

一、处理模态窗口: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弹出窗口

处理方式如下:

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

相应示例代码如下:

<!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>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905