【发布时间】:2017-03-28 12:54:45
【问题描述】:
我正在尝试为 Gmail 构建 Selenium 自动化框架。 我已经安装了以下工具: JDK、Eclipse、Selenium 罐子、Gradle、TestNG
我正在尝试登录 gmail。但是当我输入我的用户名时,我会遇到错误。 它试图在输入用户名之前单击“下一步”按钮。
我可以在开发框架时在任何需要的地方使用wait 吗?
致电wait 时是否需要保持任何标准。
编写任何用户定义的wait 方法。
错误: 失败:gmailLoginShouldBeSuccessful 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();
}
【问题讨论】:
-
设置密码时应使用 pwdTextBox 而不是 userTextBox
-
嗨,等待调整在 WATIR(Selenium 包装器)中做得非常好,它检查是否存在?,可见?,启用?可写?在它与任何元素交互之前,如果它延迟了这四个元素中的任何一个,它就会等待。试试看。
-
有一个用于 gmail 的 API。为什么不使用它而不是自动化 UI?
-
输入文字后可以使用Thread.sleep()。如果这可行,那么继续进行一些显式等待()和元素的可见性。