Untitled
Anonymous
Plain Text
10/14/2025 10:28 PM
2.0 KB
12
Indexable
Never
public boolean handleAuthorizationPopupIfPresent(WebDriverWait wait) {
final WebDriver driver = runner.getDriver();
final String original = driver.getWindowHandle();
// brak popupu -> wracamy cicho
if (driver.findElements(authorizeButton).isEmpty()) {
logger.atInfo().log("Authorization popup not present.");
return false;
}
// 1) Klik przez FluentWait (bez ręcznych prób i bez szerokiego catch)
FluentWait<WebDriver> fw = new FluentWait<>(driver)
.withTimeout(wait.getTimeout())
.pollingEvery(Duration.ofMillis(200))
.ignoring(StaleElementReferenceException.class)
.ignoring(ElementClickInterceptedException.class);
try {
fw.until(d -> {
WebElement btn = ExpectedConditions.refreshed(
ExpectedConditions.elementToBeClickable(authorizeButton)
).apply(d);
if (btn == null) return false;
((JavascriptExecutor) d).executeScript(
"arguments[0].scrollIntoView({block:'center'})", btn);
btn.click();
return true;
});
} catch (TimeoutException te) {
logger.atInfo().log("Authorize button not clickable within timeout; skipping.");
return false;
}
// 2) Opcjonalne nowe okno (miękko)
Set<String> before = driver.getWindowHandles();
try {
new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.numberOfWindowsToBe(before.size() + 1));
// przełącz na nowe, kliknij email, wróć
String newWin = driver.getWindowHandles().stream()
.filter(h -> !before.contains(h)).findFirst().orElse(null);
if (newWin != null) {
driver.switchTo().window(newWin);
try {
new WebDriverWait(driver, Duration.ofSeconds(10))
.until(ExpectedConditions.elementToBeClickable(email))
.click();
} finally {
driver.switchTo().window(original);
}
}
} catch (TimeoutException ignore) {
logger.atInfo().log("No new window after authorize; continue.");
}
logger.atInfo().log("Authorization popup handled.");
return true;
}Editor is loading...
Leave a Comment