Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
How to verify certain text is displayed on the page/element?

I'm trying to capture screenshots using selenium webdriver on a page that has textarea with a large scrollable text. I need to capture screenshots of all the texts in the textarea. With my code, I am able to scroll down on the textarea and take screenshots but need to stop once all the texts are shown. Here is the code

    while(!textDisplayedInPage("text at the bottom of textarea element")){
        takeScreenShot();
        scrollDown();
       }
    

public boolean textDisplayedInPage(String text){
    WebElement element = null;
    try{
        element =getDriver().findElement(By.xpath("//*[contains(text(),'"+text+"')]"));
    }catch (Exception e){}
    if(element != null){
        return true;
    };
    return false;
}

enter image description here

problem is the textDisplayedInPage() method doesn't work and selenium finds the element on the first screen even though it's not displayed yet and breaks the loop. I have tried few answers that I found of similar issues here but all fails to deliver what's displayed. Any insight on how to capture or verify displayed text of a scrollable element would help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When Selenium looks for an element it checks inside DOM-tree and even though you can't see whole text yet it's in there. If you need to retrieve and verify some text than probably element.getText() would be enough for this, but if you absolutely need to take screenshots thеn you can use JavaScriptExecutor and some scrolling down JS code:

 JavascriptExecutor js = (JavascriptExecutor) driver;
 js.executeScript("document.getElementById(id_attribute_value).scrollHeight;", "");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!