zoukankan      html  css  js  c++  java
  • 弹出对话框的处理

    JavaScript共有3中弹出对话框Alert、Confirmation以及Prompt。
    1. Alert:警告对话框,只有一个确定的按钮
    2. Confirmation:确认对话框,一般是一个确定和取消按钮
    3. Prompt:输入对话框,需要输入内容
    方法:
    • Accept() 单击弹出对话框的确认按钮
    • Dismiss() 单击弹出对话框的取消按钮
    • SendKeys(keysToSend) 在弹出对话框中输入文本,该方法值对Prompt弹出对话框有效
    • getText() 用于获取弹出对话框的文本内容
     
    例子:
    public static void main(String[] args) throws InterruptedException {
     
      System.setProperty("webdriver.firefox.bin", "F:\firefox\firefox.exe");
      WebDriver driver = new FirefoxDriver();
      driver.navigate().to("file:///C:/Users/yunling/Desktop/testPage.html");
      System.out.println("正确获取URL: "+driver.getCurrentUrl().equals("file:///C:/Users/yunling/Desktop/testPage.html"));
     
      driver.findElement(By.xpath("html/body/input[1]")).click();
      Thread.sleep(2000);
      System.out.println(driver.switchTo().alert().getText()); //输出获取弹出对话框的内容
      driver.switchTo().alert().accept(); //单击对话框的确定按钮
      driver.findElement(By.xpath("html/body/input[2]")).click();
      Thread.sleep(2000);
      driver.switchTo().alert().dismiss(); //单击对话框的取消按钮
      driver.findElement(By.xpath("html/body/input[3]")).click();
      Thread.sleep(2000);
      System.out.println(driver.switchTo().alert().getText());
      driver.switchTo().alert().sendKeys("这就是输入的内容");
      driver.switchTo().alert().accept();
    }
  • 相关阅读:
    linux--->curl
    linux--->定时任务
    php--->无限级分类
    php--->自己封装的简易版mvc框架
    php--->单例模式封装mysql操作类
    Linux使用退格键时出现^H ^?解决方法
    错误日志
    linux下redis服务器安装使用 安装php的redis扩展 安装laravel下的redis
    php system()
    laravel redis的使用
  • 原文地址:https://www.cnblogs.com/wysk/p/7511880.html
Copyright © 2011-2022 走看看