Упомянутый URL-адрес в коде занимает 5 секунд, чтобы отобразить экран входа в систему, и для того, чтобы ввести данные на странице входа, я реализовал в своем коде свободное ожидание в течение 10 секунд. Несмотря на то, что ожидание указано правильно, по какой-то причине это ожидание не выполняется, и я всегда отображаюсь с org.openqa.selenium.NoSuchElementException: нет такого элемента: Невозможно найти элемент:
КОД:
public class FluentWaitDemo {
public static void main(String[] args) throws InterruptedException
{
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://app.hubspot.com/login");
By email = By.xpath("//input[@type='email']");
WebElement userId = FluentWaitForElement(driver, email);
userId.sendKeys("*******@gmail.com");
driver.close();
}
public static WebElement FluentWaitForElement(WebDriver driver, By locator)
{
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(Duration.ofSeconds(10))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(NoSuchElementException.class);
return wait.until(ExpectedConditions.presenceOfElementLocated(locator));
}
}
Ошибка:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@type='email']"}
(Session info: chrome=83.0.4103.97)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html