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

135
Views
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 answers
Answer question

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 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!