zoukankan      html  css  js  c++  java
  • [selenium webdriver Java]显示的等待同步

    显示等待可以在执行下一次操作时,自定义等待条件

    显示的等待只需要执行在需要同步的地方而不影响脚本的其他地方

    Selenium WebDriver提供了WebDriverWait和ExpectedCondition类来执行显示等待

    ExpectedCondition类提供了一系列预定义好的条件来等待。下面是一些常用的条件

    预定义条件 方法名
    元素可见可点击 elementToBeClickable(By locator)
    元素可被选中 elementToBeSelected(WebElement element)
    存在一个元素 presenceOfElementLocated(By locator)
    元素中出现指定的文本 textToBePresentInElement(By locator)
    元素的值 textToBePresentInElementValue(By locator, String text)
    标题

    titleContains(String title)

    WebDriverWait每500毫秒调用一次ExpectedCondition直到得到正确的返回值。这样的好处是随时控制所需呀等待的地方,更加精确的控制等待条件

     1 public void testWithImplicitWait(){
     2     System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
     3     WebDriver driver = new ChromeDriver();
     4     driver.get("http://map.baidu.com");
     5 
     6         WebElement curCity = driver.findElement(By.id("curCity"));
     7     curCity.click();
     8     
     9     //设置等待时间10秒
    10     WebDriverWait wait = new WebDriverWait(driver,10);
    11     //等待直到符合元素文本内容出现
    12     wait.until(ExpectedConditions.textToBePresentInElement(By.id("selCityHotCityId"), "全国"));
    13     
    14         driver.quit();
    15 }
    示例代码

  • 相关阅读:
    SpringApplication类-1
    post与head注入
    sql_post注入
    渗透测试点线面合集
    渗透入侵溯源
    VMware 安装Tools 失败的问题:VGAuthService 启动失败
    Weblogic wls-wsat XMLDecoder 反序列化漏洞复现(CVE-2017-10271)
    web常见的中间件漏洞及复现
    XX点评H5字体映射
    python控制阿里云服务器开机,关机,重启
  • 原文地址:https://www.cnblogs.com/missPersist/p/4204333.html
Copyright © 2011-2022 走看看