zoukankan      html  css  js  c++  java
  • WebDriver的等待方式

    /*
     * 1.线程休眠
     * 2.隐式等待
     * 3.显示等待
     * 
     */
    package com.sfwork;
    
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.NoSuchElementException;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class WebWait {
    
        public static void main(String[] args) throws InterruptedException {
            // TODO Auto-generated method stub
            //设置WebDriver的路径
    //        System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\"
    //                + "Application\\chromedriver.exe");
            System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\"
                    + "Mozilla Firefox\\geckodriver.exe");
            //创建webdriver对象,控制浏览器
    //        WebDriver driver = new ChromeDriver();
            WebDriver driver = new FirefoxDriver();
            //设置打开浏览器的网址
            driver.navigate().to("http://www.baidu.com");
            //设置浏览器最大化
            driver.manage().window().maximize();
            //线程休眠
    //        Thread.sleep(3000);
            //隐式等待,全局的
    //        driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    //        driver.findElement(By.id("22"));
            //显示等待,针对特定的一个元素
            WebDriverWait wait = new WebDriverWait(driver,15);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("22")));
            //关闭webdriver
            driver.close();
            
        }
    
    }
  • 相关阅读:
    webservice的几种调用方式
    捕获的异常到控制台的的信息转为String输出,在保存日志方面有用
    IO文件的读取与写入
    eclipse修改内存大小
    Oracle序列的创建与删除
    NFS挂载-实现文件共享
    arraylList.add(int,obj)的底层是怎么样的??
    Oracle修改表字段数据类型
    SVN版本库打包迁移备份恢复
    linux中tar详解
  • 原文地址:https://www.cnblogs.com/evangline/p/6913237.html
Copyright © 2011-2022 走看看