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);