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对话框中输入文字点击确定之后,将会刷新页面,显示出这些文字

  1. import org.openqa.selenium.Alert;
  2. import org.openqa.selenium.By;
  3. import org.openqa.selenium.WebDriver;
  4. import org.openqa.selenium.firefox.FirefoxDriver;
  5. public class DialogsStudy {
  6. /**
  7. * @wuyepiaoxue
  8. */
  9. public static void main(String[] args) {
  10. // TODO Auto-generated method stub
  11. System.setProperty("webdriver.firefox.bin","D:/Program Files (x86)/Mozilla Firefox/firefox.exe");
  12. WebDriver dr = new FirefoxDriver();
  13. String url = "file:///C:/Users/Administrator/Desktop/test.htm";
  14. dr.get(url);
  15. //点击第一个按钮,输出对话框上面的文字,然后叉掉
  16. dr.findElement(By.id("alert")).click();
  17. Alert alert = dr.switchTo().alert();
  18. String text = alert.getText();
  19. System.out.println(text);
  20. alert.dismiss();
  21. //点击第二个按钮,输出对话框上面的文字,然后点击确认
  22. dr.findElement(By.id("confirm")).click();
  23. Alert confirm = dr.switchTo().alert();
  24. String text1 = confirm.getText();
  25. System.out.println(text1);
  26. confirm.accept();
  27. //点击第三个按钮,输入你的名字,然后点击确认,最后
  28. dr.findElement(By.id("prompt")).click();
  29. Alert prompt = dr.switchTo().alert();
  30. String text2 = prompt.getText();
  31. System.out.println(text2);
  32. prompt.sendKeys("jarvi");
  33. prompt.accept();
  34. }
  35. }

Selenium对于对话框alert,confirm,prompt的处理的更多相关文章

  1. selenium自动化测试入门 Alert/Confirm/Prompt 弹出窗口处理

    一.Alert/Confirm/Prompt弹出窗口特征说明 Alert弹出窗口: 提示用户信息只有确认按钮,无法通过页面元素定位,不关闭窗口无法在页面上做其他操作. Confirm 弹出窗口: 有确 ...

  2. Java Selenium - 几种对话框处理Alert\confirm\prompt

    1. Alert , 先用常规办法定位到能触发alert的按钮 , 然后 Alert alert = driver.switchTo().alert(); alert.accept(); 如果aler ...

  3. selenium python (十一)alert/confirm/prompt的处理(js中的弹出框)

    webdriver中处理js所生成的alert.confirm以及prompt,采用switch_to_alert()方法定位到alert/confirm/prompt.然后使用text/accept ...

  4. Python+Selenium学习--alert/confirm/prompt 处理

    场景 webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confi ...

  5. alert/confirm/prompt 处理

    webdriver 中处理JavaScript 所生成的alert.confirm 以及prompt 是很简单的.具体思路是使用switch_to_alert()方法定位到alert/confirm/ ...

  6. 转:python webdriver API 之alert/confirm/prompt 处理

    webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/conf ...

  7. 2.11 alert\confirm\prompt

    2.11 alert\confirm\prompt 前言   不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用 ...

  8. Selenium2学习(十二)-- alert\confirm\prompt

    前言 不是所有的弹出框都叫alert,在使用alert方法前,先要识别出到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决. alert\confirm\prompt ...

  9. Python脚本控制的WebDriver 常用操作 <二十二> 处理alert / confirm / prompt

    测试用例场景 webdriver中处理原生的js alert confirm 以及prompt是很简单的.具体思路是使用switch_to.alert()方法定位到alert/confirm/prom ...

  10. 如何模拟alert/confirm/prompt实现阻断程序运行

    场景:在执行js的时候,我们希望运行到某处,进行用户交互,根据交互的内容,运行下面的程序:下面的js程序需要用的和用户交互的内容,所以,和用户交互时,后面的程序必须停止运行 方案: 1. 原生的ale ...

随机推荐

  1. 一个"Median Maintenance"问题

    题目要求: Download the text file here. The goal of this problem is to implement the "Median Mainten ...

  2. Linux系统目录结构介绍

    参考博客: http://www.cnblogs.com/chensiqiqi/p/6243549.html 感谢原博主为我学习Linux指明方向!! linux目录:一切从“根”开始,“/”是所有目 ...

  3. Your password does not satisfy the current policy requirements

    创建用户,做测试想设置一个简单的密码.报错: 大概是MySQL5.7搞事情,默认安装了validate_password插件. mysql> SHOW VARIABLES LIKE 'valid ...

  4. seajs源码阅读

    乘着周日有点时间,阅读一下玉伯大神的源码. seajs的源码写得真的很好,很是佩服,工整美观不愧是大神,造福百姓. 说起seajs不得不说,AMD和CMD的区别.  CMD 推崇依赖就近,AMD 推崇 ...

  5. Android 测试 Appium、Robotium、monkey等框架或者工具对比

    1. Appium测试 (功能测试,用户接受度测试,黑盒测试) - Rating: 8 Appium测试相当于黑盒测试.只是测试UI逻辑正确性.所以Appium测试框架提供的方法有限.获取一个Appi ...

  6. 阿里云服务器linux(cenos)下 jdk、tomcat的安装配置

    一.JDK的安装与环境配置 1. 下载jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-213315 ...

  7. mybatis存取blob对象+@Cacheable实现数据缓存

    参考文档: http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-cache/ 需求场景: 当前业务通过第三方接口查询一个业务数据, ...

  8. java操作DBF的使用

    1.引入javadbf.4.1.jar 2. import com.linuxense.javadbf.DBFField;   import com.linuxense.javadbf.DBFRead ...

  9. string.trim().length()的用法

    public class Test{ public static void main(String args[]){ String data = " a bc "; //调用str ...

  10. ArcGisEngine图层操作(随笔,不全)

    1.加载图层: 1.1 object.AddLayer(Layer[,toindex=0]) Layer表示ILayer对象,必选,toIndex参数表示图层索引(长整型),没需求可以忽略. 1.2 ...