如何在Selenium Junit中使用WebDriverWait进行各种方法?

时间:2014-09-15 17:14:58

标签: java selenium junit4

我的代码中有各种方法,我需要使用WebDriverWait。通常我们在main方法中声明它:WebDriverWait mywait = new WebDriverWait(driver,25)。 虽然在selenium中使用junit没有主要的方法,但是如何在我的代码中以各种方法使用WebDriverWait for the mebelements ???

1 个答案:

答案 0 :(得分:0)

  1. 你可以从main调用你的JUN​​It函数。
  2. 这里有一些帮助:How do I run JUnit tests from inside my java application?

    1. 或者您只需添加Thread.sleep(millisecodns)

      即可

      尝试{     了Thread.sleep(100); } catch(InterruptedException e){     // TODO自动生成的catch块     e.printStackTrace(); }

    2. 它必须在JAVA(Eclipse)中运行 但你也可以使用(我认为更适合测试:):

      FluentWait fluentWait = new FluentWait<>(webDriver) {
        .withTimeout(30, TimeUnit.SECONDS)
        .pollingEvery(200, TimeUnit.MILLISECONDS);
        .ignoring(NoSuchElementException.class);
      }
      
      WebElement element = (new WebDriverWait(driver, 10))
         .until(ExpectedConditions.elementToBeClickable(By.id("someid")));
      

      来源:https://stackoverflow.com/a/20903328/2147581