0

On clicking the link "Click to load get data via Ajax!" in the below site text will appear, I am trying to print it after it's visible using explicit wait. it is not printing the text

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Explicitwait {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Aditya\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("http://www.itgeared.com/demo/1506-ajax-loading.html");
        System.out.println(driver.findElement(By.xpath("//*[@id='results']")).isDisplayed());//false
        driver.findElement(By.xpath("//*[@id='content']/a[2]")).click();
        System.out.println("click on the link");
        WebDriverWait d = new WebDriverWait(driver, 10);
        d.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='results']")));
        System.out.println(driver.findElement(By.xpath("//*[@id='results']")).isDisplayed());//true
        System.out.println(driver.findElement(By.xpath("//*[@id='results']")).getText());
    }

}
2
  • Are you getting any error or the text is not getting printed ? Commented Feb 16, 2019 at 7:23
  • earlier text was not getting printed.....after changing it to visibility from presence it worked and is getting printed Commented Feb 16, 2019 at 10:26

1 Answer 1

3

To get text use visibilityOfElementLocated instead of presenceOfElementLocated:

WebDriverWait d = new WebDriverWait(WebDriverRunner.getWebDriver(), 10);
d.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='results']")));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks...changed to visibility from presence it worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.