In my opinion, it is important to understand the functionality of the button
Whenever there are changes in the UI,
Using ExpectedConditions.visibilityOf(WebElement element) could offer a more effective solution
If JavaScript returns true or false, the driver will wait for the script execution result
new WebDriverWait(driver, Duration.ofSeconds(20)).until(new ExpectedCondition<Boolean>(){
public Boolean apply(WebDriver driver) {
JavascriptExecutor js = (JavascriptExecutor) driver;
return (Boolean) js.executeScript("console.log('wait');return 1+1==2");
}
});