Java 代码中的Selenium Fluent Wait实现仍然给出;org.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:";
代码中提到的URL显示登录屏幕需要5秒钟,为了在登录页面上输入详细信息,我在代码中实现了fluent wait 10秒钟。尽管正确地提到了等待,但由于某些原因,此等待没有得到遵守,并且我始终显示为org.openqa.selenium.NoSuchElementException:无此类元素:无法找到元素: 代码: 要在电子邮件地址字段中发送字符序列,您必须为Java 代码中的Selenium Fluent Wait实现仍然给出;org.openqa.selenium.NoSuchElementException:没有这样的元素:无法定位元素:";,java,selenium,xpath,css-selectors,nosuchelementexception,Java,Selenium,Xpath,Css Selectors,Nosuchelementexception,代码中提到的URL显示登录屏幕需要5秒钟,为了在登录页面上输入详细信息,我在代码中实现了fluent wait 10秒钟。尽管正确地提到了等待,但由于某些原因,此等待没有得到遵守,并且我始终显示为org.openqa.selenium.NoSuchElementException:无此类元素:无法找到元素: 代码: 要在电子邮件地址字段中发送字符序列,您必须为元素tobelickable()归纳,并且您可以使用以下任一选项: 使用cssSelector: 使用xpath: 浏览器快照:
元素tobelickable()
归纳,并且您可以使用以下任一选项:
- 使用cssSelector:
- 使用xpath:
参考文献 您可以在中找到关于的两个详细讨论:
元素tobelickable()
导出字符序列,并且您可以使用以下任一选项:
- 使用cssSelector:
- 使用xpath:
参考文献 您可以在中找到关于的两个详细讨论:
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
driver.get("https://app.hubspot.com/login");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#username"))).sendKeys("Bimlesh@gmail.com");
driver.get("https://app.hubspot.com/login");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='username']"))).sendKeys("Bimlesh@gmail.com");