Hi,
Whilst it’s OK and valid to use Thread.sleep to give the browser time to catch-up, it is generally seen as a bad practice. For example, what if the element starts to appear in 1 second? Your thread is going to wait another 4 seconds before proceeding. Is 5 seconds always going to be long enough? Again, you could whack this up to 10 and be 99% certain, but you’re just making your test slower.
You might want to look for examples using presenceOfElementLocated. E.g.
element = (new WebDriverWait(this.webDriver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id(elementId)));
The above will look for the element in question for up to 10 seconds, before error, but on the plus side, once it’s found the test resumes.