-1

I need to do this 1. http://the-internet.herokuapp.com/dynamic_loading/1 2. Use Explicit Wait for 30 seconds 3. Click on start button and verify Hello World!.

I have written the following code but element.getText is null.

    driver.get("http://the-internet.herokuapp.com/dynamic_loading/1");
    WebDriverWait wait=new WebDriverWait(driver, 30);
    WebElement all=driver.findElement(By.xpath("//*[@id='start']/button"));
    all.click();
    WebElement element=wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='finish']/h4")));
    driver.findElement(By.xpath("//*[@id='finish']/h4"));
    String text=element.getText();
    System.out.println("hi:"+text);
    //assertEquals("Hello World!", text);
Wait
  • 1
  • 3

1 Answers1

1

Change ExpectedConditions.presenceOfElementLocated

to

ExpectedConditions.visibilityOfElementLocated

When you use presenceOfElementLocated, it checks the DOM to see if it finds the specified element, no matter what it's visibility is. Hence you find the text to be null, as the element is present in DOM but is not yet visible.

On the other hand, visibilityOfElementLocated checks if the specified element is available and also visible.

Jayesh Doolani
  • 1,233
  • 10
  • 13