zoukankan      html  css  js  c++  java
  • Selenium+Java显示等待和隐式等待

      描述:用来操作界面上的等待时间,显示等待是等待某一条件满足,条件满足后进行后面的操作;隐式等待是给出一个等待时间,在时间到达之前若满足条件,则立即执行后续操作。

      

    public class TestSelenium {
        
        WebDriver webDriver = null;
        
        @Before
        public void Setup(){
            File chromeDriverPath = new File("D:\Selenium\webdriver\chromedriver.exe");
            System.setProperty("webdriver.chrome.driver", chromeDriverPath.getAbsolutePath());
            webDriver = new ChromeDriver();
        }
      @Test
        public void testWait(){
            webDriver.get("http://www.baidu.com");
            
            WebElement webElement = webDriver.findElement(By.name("wd"));
            webElement.sendKeys("Selenium 2");
            webElement.submit();
            
            //1. 显示等待
            (new WebDriverWait(webDriver, 10)).until(new ExpectedCondition<Boolean>() {
    
                @Override
                public Boolean apply(WebDriver driver) {
                    // TODO Auto-generated method stub
                    return driver.getTitle().toLowerCase().startsWith("selenium");
                }
                
            });
            
            System.out.println("Page title is:"+webDriver.getTitle());
            
            webDriver.navigate().back();
            
            //2. 隐式等待
            webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            
            webDriver.findElement(By.xpath("//*[@id="u1"]/a[1]")).click();
            
            webDriver.quit();
        }
    }

      

  • 相关阅读:
    Git远程库
    Git的使用
    如何利用IO流复制文件
    Lambda表达式
    Lambda表达式的标准格式
    线程池的使用步骤
    解决线程安全的三个方法
    多线程
    位运算
    如何用javadoc生成java帮助文档
  • 原文地址:https://www.cnblogs.com/yigui/p/7200853.html
Copyright © 2011-2022 走看看