【发布时间】:2015-05-21 14:58:03
【问题描述】:
我想知道是否有人可以帮助我解决我正在尝试解决的问题以及用于 Webdriver 的 Java 中的 If 语句。
登录我正在测试的应用程序时,可能会在主页之前进入安全问题页面(如果是新用户等)。我希望测试中的代码在出现安全问题页面时填写并继续,如果没有,请检查您是否在主页上。
我可以在 Selenium RC 中使用
if (selenium.isTextPresent("User Account Credentials Update")) {
selenium.type("//input[@id='securityQuestion']", "A");
selenium.type("//input[@id='securityAnswer']", "A");
selenium.type("//input[@id='emailAddress']", "test@test.com");
selenium.click("update");
selenium.waitForPageToLoad("30000");
}
assertTrue(selenium.isTextPresent("MainPage"));
玩弄我正在使用的 Webdriver:
if(driver.findElement(By.id("securityQuestion")) != 0) {
driver.findElement(By.id("securityQuestion")).sendKeys("A");
driver.findElement(By.id("securityAnswer")).sendKeys("A");
driver.findElement(By.id("emailAddress")).sendKeys("test@test.com");
driver.findElement(By.id("update")).click();
Assert.assertTrue("Main Page is not Showing",
driver.getPageSource().contains("MainPage"));
这样做的问题是,如果未显示安全屏幕,它总是会抛出异常。如果没有显示该页面,我需要如何设置代码以便它忽略安全页面内容? 谢谢你的帮助:-)
【问题讨论】:
-
你遇到了什么异常?