-1

I have various methods in my code in which I need to use WebDriverWait. Usually we declare it in the main method like:

WebDriverWait mywait = new WebDriverWait(driver, 25)

While using JUnit in Selenium, there isn't any main method. How can I use WebDriverWait for webelements in various methods in my code?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0

Way you can call your JUnit function from main

Here is some help on how to: How do I run JUnit tests from inside my Java application?

Or you can simply add Thread.sleep(millisecond)

try {
    Thread.sleep(100);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

It must work in Java (Eclipse).

But you can also use (I think it is better for testing):

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")));

Source: How can make it wait until an element is present in Selenium?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SüniÚr
  • 826
  • 1
  • 16
  • 33