0

I want to capture the text that is produced after clicking one of the links. But instead what i end up doing is capturing the text of the link.

Snippet of the code I am using:

driver.navigate().to("https://demoqa.com/links");
driver.findElement(By.xpath("/html/body/div[2]/div/div/div[2]/div[2]/div[2]/p[3]/a")).click();
System.out.println(driver.findElement(By.xpath("//*[@id=\'linkResponse\']")).getText());

I have been trying to use getText(). But i don't know how to get text generated from the link.

Snapshot of the page:

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

Within the DEMOQA website to click on the link with text Create and print the generated text you need to you need to induce WebDriverWait and you can use either of the following locator strategies:

  • Code block:

    driver.get("https://demoqa.com/links");
    new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.elementToBeClickable(By.linkText("Created"))).click();
    System.out.println(new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[./b]"))).getText());
    
  • Console output:

    Link has responded with staus 201 and status text Created
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352