gpt4 book ai didi

java - 在 Selenium Webdriver 中,在文本框中输入文本后单击按钮

转载 作者:太空宇宙 更新时间:2023-11-04 11:38:03 25 4
gpt4 key购买 nike

我正在尝试为 Gmail 构建 Selenium 自动化框架。我已经安装了以下工具:JDK、Eclipse、Selenium Jars、Gradle、TestNG

我正在尝试登录 Gmail。但当我输入用户名时,我遇到了以下错误。它尝试在输入用户名之前单击“下一步”按钮。

在开发框架时,我可以在需要时使用wait吗?在调用 wait 时我是否需要维护任何标准?编写任何用户定义的wait方法。

错误:失败:gmail登录应该成功org.openqa.selenium.ElementNotVisibleException:无法单击元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:207 毫秒

我的代码:

@Test
public void gmailLoginShouldBeSuccessful(){
//1.Go to Gmail website
System.setProperty("webdriver.ie.driver", "C:\\Selenium_Softwares_Docs_Videos\\IEDriverServer_x64_3.1.0\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("http://gmail.com");
//2.Fill in username
WebElement userTextBox = driver.findElement(By.id("Email"));
userTextBox.clear();
userTextBox.sendKeys("xxxx");
//3. click on next button
WebElement nxtBtn = driver.findElement(By.id("next"));
nxtBtn.click();
//4.Fill in password
WebElement pwdTextBox = driver.findElement(By.id("Passwd-hidden"));
userTextBox.clear();
userTextBox.sendKeys("xxxxxxx");
//5.Click sign in
WebElement signBtn = driver.findElement(By.id("signIn"));
signBtn.click();
}

最佳答案

您可以使用显式等待来实现您的要求。

WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//xpath_to_element")));

Webdriver 将等待 5 秒才能单击您的元素。

关于java - 在 Selenium Webdriver 中,在文本框中输入文本后单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43070163/

25 4 0
文章推荐: c++ - 如何从点源模拟二维球面波?
文章推荐: c++ - 在 Linux 和 Mac 上处理可移动媒体 USB/CD-ROM 挂载/卸载事件
文章推荐: html -
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com