Если вы знаете, как проверить, что пользовательский интерфейс полностью загружен, вы можете использовать ожидание занятости:
busyWaitFor(() -> isUILoaded(), 10000, 200);
с busyWaitFor
, реализованным следующим образом:
private static boolean busyWaitFor(BooleanSupplier condition, int timeoutMilSec, int checkIntervalMilSec) {
long startTime = System.currentTimeMillis();
boolean interrupted;
do {
if (condition.getAsBoolean()) {
return true;
}
boolean timeoutReached = System.currentTimeMillis() - startTime >= (long)timeoutMilSec;
if (timeoutReached) {
return false;
}
interrupted = sleep(checkIntervalMilSec);
} while(!interrupted);
return false;
}