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

139
Visualizações
How to stop looking for an element after a certain period using JavaScriptExecutor on an unlimited screen like Facebook?

Suppose I want to look for my post on a Facebook page by scrolling down. And I am looking my post based on my profile name. I use JavascriptExecutor to start scrolling down until it finds the post but what if it won't get my post on the page then how can I stop the executor after certain period of time as Facebook page keeps updating and loading in seconds as we go down and down. It will go in continuous loop. Any suggestions would help.

Example:

WebElement element = driver.findByElement(By.name("Myname"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", element);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This will execute any code inside the while loop for a pre-defined amount of time. In this example I have it set to print out an incrementing variable for 5 seconds.

int i = 0;
    
    long start = System.currentTimeMillis();
    long end = start + 5 * 1000;
    while (System.currentTimeMillis() < end) {
        System.out.println(i);
        i++;
    }

So for you it'd be -

    long start = System.currentTimeMillis();
    long end = start + desiredTimeDuration(inSeconds) * 1000;
    while (System.currentTimeMillis() < end) {
        whatYouWantItToDoForSetAmountOfTime
    }

Hope this helps, cheers!

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