To avoid using the Thread.sleep in Selenium you have two types of waits, implicit and explicit .
The implied waits is the time that WebDriver waits to find an item that is not available and is defined when the WebDriver is created >.
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Explicit waits is the amount of time you wait until a condition is met to search for an item.
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
.until (ExpectedConditions.presenceOfElementLocated (By.id ("myDynamicElement")));
There are many types of conditions such as an element that is visible, clickable, its value is X, etc. etc.
Here you have a link with the Selenium documentation where they explain in more detail the waits and the types of waits:
link
And here the Selenium documentation with all types of conditions:
link