Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda