• 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();
        }
    }

      

  • 相关阅读:
    刻意练习:从一般到卓越的方法
    Spring JMS 整合 ActiveMQ
    冒泡排序 快速排序
    TCP协议,UDP 协议的区别
    HashMap实现原理
    java 类加载过程
    Linux-vim命令(3)
    Linux-vim命令(2)
    Linux-vim命令(1)
    Linux-命令里的快捷键
  • 原文地址:https://www.cnblogs.com/yigui/p/7200853.html
Copyright © 2020-2023  润新知