-2

I am getting Null pointer exception error in line "wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(ElementPath)));" in below code.

Could you please help me on this.

private static FluentWait<WebDriver> wait;
String  ElementPath = null;
clickAnElementByLinkText(ElementPath);
public static void clickAnElementByLinkText(String ElementPath) {        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(ElementPath)));        
    driver.findElement(By.xpath(ElementPath)).click();
}

1 Answers1

0

wait object is null because the instance never created before used.

private static FluentWait<WebDriver> wait = ;

Instead of above line use following :

WebDriver driver = new FirefoxDriver(); 
private Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
       .withTimeout(30, SECONDS)
       .pollingEvery(5, SECONDS)
       .ignoring(NoSuchElementException.class);

See More https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/FluentWait.html

http://toolsqa.com/selenium-webdriver/implicit-explicit-n-fluent-wait/

Bhuwan Prasad Upadhyay
  • 2,916
  • 1
  • 29
  • 33