Code: Select all
FluentWait fluentWait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofMillis(200))
.ignoring(NoSuchElementException.class);
WebElement countryMx = initCountry.getMx();
fluentWait.until(d -> ExpectedConditions.visibilityOf(countryMx));
System.out.println("Element MX should be visible by now");
fluentWait.until(d -> ExpectedConditions.elementToBeClickable(countryMx));
System.out.println("Element MX should be clickable by now");
do {
executor.executeScript("arguments[0].scrollIntoView(true);", countryMx);
} while (!countryMx.isDisplayed());
countryMx.click();
Code: Select all
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#MX"}
< /code>
Wenn ich den alternativen Ansatz versuche: < /p>
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(1));
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("MX")));
WebElement countryMx = initCountry.getMx();
do {
executor.executeScript("arguments[0].scrollIntoView(true);", countryMx);
} while (!countryMx.isDisplayed());
countryMx.click();
< /code>
Es funktioniert in Ordnung. Darüber hinaus möchte ich einen Ansatz und eine Syntax, die für die Verwendung mit dem PageObject-Muster sauber sind.fluentWait.until(d -> ExpectedConditions.presenceOfElementLocated(By.id("MX")));