Selenium对于对话框alert,confirm,prompt的处理
html 源码:
<html>
<head>
<title>Alert</title>
<script>
function myFunction()
{
var x;
var b = prompt("hello","harry potter");
if (b!=null && b!="") {
x = "hello"+b+"欢迎你";
}
document.getElementById("display").innerHTML=x;
}
</script>
</head>
<body>
<input id = "alert" value = "alert" type = "button" onclick = "alert('欢迎!请按确认继续!');"/>
<input id = "confirm" value = "confirm" type = "button" onclick = "confirm('确定吗?');"/>
<input id = "prompt" value = "prompt" type = "button" onclick = "myFunction()" />
<p id = "display"></p>
</body>
</html>
以上html代码在页面上显示了三个按钮,点击他们分别弹出alert、confirm、prompt对话框。如果在prompt对话框中输入文字点击确定之后,将会刷新页面,显示出这些文字
- import org.openqa.selenium.Alert;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- public class DialogsStudy {
- /**
- * @wuyepiaoxue
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.setProperty("webdriver.firefox.bin","D:/Program Files (x86)/Mozilla Firefox/firefox.exe");
- WebDriver dr = new FirefoxDriver();
- String url = "file:///C:/Users/Administrator/Desktop/test.htm";
- dr.get(url);
- //点击第一个按钮,输出对话框上面的文字,然后叉掉
- dr.findElement(By.id("alert")).click();
- Alert alert = dr.switchTo().alert();
- String text = alert.getText();
- System.out.println(text);
- alert.dismiss();
- //点击第二个按钮,输出对话框上面的文字,然后点击确认
- dr.findElement(By.id("confirm")).click();
- Alert confirm = dr.switchTo().alert();
- String text1 = confirm.getText();
- System.out.println(text1);
- confirm.accept();
- //点击第三个按钮,输入你的名字,然后点击确认,最后
- dr.findElement(By.id("prompt")).click();
- Alert prompt = dr.switchTo().alert();
- String text2 = prompt.getText();
- System.out.println(text2);
- prompt.sendKeys("jarvi");
- prompt.accept();
- }
- }
Selenium对于对话框alert,confirm,prompt的处理的更多相关文章
- selenium自动化测试入门 Alert/Confirm/Prompt 弹出窗口处理
一.Alert/Confirm/Prompt弹出窗口特征说明 Alert弹出窗口: 提示用户信息只有确认按钮,无法通过页面元素定位,不关闭窗口无法在页面上做其他操作. Confirm 弹出窗口: 有确 ...
- Java Selenium - 几种对话框处理Alert\confirm\prompt
1. Alert , 先用常规办法定位到能触发alert的按钮 , 然后 Alert alert = driver.switchTo().alert(); alert.accept(); 如果aler ...
- selenium python (十一)alert/confirm/prompt的处理(js中的弹出框)
webdriver中处理js所生成的alert.confirm以及prompt,采用switch_to_alert()方法定位到alert/confirm/prompt.然后使用text/accept ...
- Python+Selenium学习--alert/confirm/prompt 处理
场景 webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confi ...
- alert/confirm/prompt 处理
webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to_alert()方法定位到alert/confirm/ ...
- 转:python webdriver API 之alert/confirm/prompt 处理
webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/conf ...
- 2.11 alert\confirm\prompt
2.11 alert\confirm\prompt 前言 不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用 ...
- Selenium2学习(十二)-- alert\confirm\prompt
前言 不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决. alert\confirm\prompt ...
- Python脚本控制的WebDriver 常用操作 <二十二> 处理alert / confirm / prompt
测试用例场景 webdriver中处理原生的js alert confirm 以及prompt是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confirm/prom ...
- 如何模拟alert/confirm/prompt实现阻断程序运行
场景:在执行js的时候,我们希望运行到某处,进行用户交互,根据交互的内容,运行下面的程序:下面的js程序需要用的和用户交互的内容,所以,和用户交互时,后面的程序必须停止运行 方案: 1. 原生的ale ...
随机推荐
- js模块化/js模块加载器/js模块打包器
之前对这几个概念一直记得很模糊,也无法用自己的语言表达出来,今天看了大神的文章,尝试根据自己的理解总结一下,算是一篇读后感. 大神的文章:http://www.css88.com/archives/7 ...
- 使用hexdump追踪FAT32文件系统中的一个文件
最近在看文件系统基础结构等知识,本来重点是想看EXT4文件系统,但是目前没有找到比较详细说明EXT4文件系统详细结构的,用EXT3的对应着找结果有点出入,在想是不是我用hexdump的参数有问题,于是 ...
- Centos7yum安装Redis详细教程
原本是在自己的mac上安装redis的,通过brew去安装的redis觉得很简单,实际macos系统与centos系统还是有一些区别的. 1.yum安装redis服务 sudo yum install ...
- php接口加密
在实际开发中PHP接口开发是PHP常见的技术,可以通过接口进行一些操作,可以访问接口获取数据,给app提供数据接口等,但是如果接口没有加密解密的过程,很容易发生盗用和不安全的操作. 下边简单介绍一下A ...
- Java之面向对象例子(三) 多态,重写,重载,equals()方法和toString()方法的重写
重写(继承关系) 子类得成员方法和父类的成员方法,方法名,参数类型,参数个数完全相同,这就是子类的方法重写了父类的方法. 重载 在一个类里有两个方法,方法名是完全一样的,参数类型或参数个数不同. 例子 ...
- CentOS的改变系统启动级别
CentOS7改变系统启动级别 systemctl命令: 文本模式:systemctl set-default multi-user.target 图形模式:systemctl set-def ...
- Python面向对象编程(三)
封装 1.为什么要封装? 封装就是要把数据属性和方法的具体实现细节隐藏起来,只提供一个接口.封装可以不用关心对象是如何构建的 2.封装包括数据的封装和函数的封装,数据的封装是为了保护隐私,函数的封装是 ...
- Java条件查询涉及到时分秒
关于Oralce数据库 的日期时间查询: 下面我们先来看一组日期数据 表:myDate 列:time; 1998-8-7 23:45:33.3 1998-8-7 11:22:21.5 1998-8-7 ...
- Docker初步了解
Docker 是什么 https://www.docker.com/ Docker 这个单词英文原意是码头工人,搬运工的意思,这个搬运工搬运的是各种应用的容器. 官方的说法是,Docker 是提供给开 ...
- 配置LAMP实现WordPress
环境说明: 在同一台主机上实现LAMP(Linux + Apache + MariaDB + PHP) CentOS 7.3.Apache 2.4.6.MariaDB 5.5.52.PHP 5.4.1 ...