【发布时间】:2015-11-26 11:44:50
【问题描述】:
您好,我正在使用 selenium webdriver,并且在运行以下脚本时,我在脚本中突出显示的位置遇到过时元素异常错误。
我的脚本停在那里,我无法运行。
错误消息是 - Stale Element 异常错误。在缓存中找不到该元素,可能页面在查找后已更改。
任何人请在这种情况下帮助我并指导我纠正这个错误。
问候, 维涅什 K S
@Test
public void testClient() throws Exception {
driver.get("http://t1accounts.govreports.com.au/?service=govreports");
driver.findElement(By.id("Password")).clear();
driver.findElement(By.id("Password")).sendKeys("Viki2607");
driver.findElement(By.id("UserName")).clear();
driver.findElement(By.id("UserName")).sendKeys("vignesh@eimpact.com.au");
driver.findElement(By.id("btnLogin")).click();
driver.findElement(By.xpath(".//*[@id='side-menu']/li[2]/a/span")).click();
driver.findElement(By.cssSelector("span.hide380")).click();
driver.findElement(By.id("Individual")).click();
//driver.wait(5);
**driver.findElement(By.id("ABN")).clear();**
driver.findElement(By.id("ABN")).sendKeys("38091241128");
driver.findElement(By.id("TFN")).clear();
driver.findElement(By.id("TFN")).sendKeys("100000001");
driver.findElement(By.id("BusinessName")).clear();
driver.findElement(By.id("BusinessName")).sendKeys("LORGE CONSULTING (AUSTRALIA) PTY LTD");
driver.findElement(By.id("TradingName")).clear();
driver.findElement(By.id("TradingName")).sendKeys("LORGE CONSULTING (AUSTRALIA) PTY LTD");
//driver.findElement(By.xpath("//ul[@id='Individual_Salutation_listbox']/li")).click();
driver.findElement(By.id("Individual_Salutation")).clear();
driver.findElement(By.id("Individual_Salutation")).sendKeys("Ms");
//new Select(driver.findElement(By.id("Individual_Salutation"))).selectByVisibleText("Mr");
//driver.findElement(By.id("Individual_Salutation")).sendKeys("Mr");
driver.findElement(By.id("Individual_FirstName")).clear();
driver.findElement(By.id("Individual_FirstName")).sendKeys("Joan");
driver.findElement(By.id("Individual_LastName")).clear();
driver.findElement(By.id("Individual_LastName")).sendKeys("Ignatius");
driver.findElement(By.id("Individual_Phone")).clear();
driver.findElement(By.id("Individual_Phone")).sendKeys("042323155");
driver.findElement(By.id("Individual_Email")).clear();
driver.findElement(By.id("Individual_Email")).sendKeys("test@govreports.com.au");
driver.findElement(By.id("PostalAddress_Line1")).clear();
driver.findElement(By.id("PostalAddress_Line1")).sendKeys("Walker Street");
driver.findElement(By.id("PostalAddress_City")).sendKeys("SYDNEY");
driver.findElement(By.id("PostalAddress_Region")).sendKeys("NSW");
driver.findElement(By.id("PostalAddress_Postcode")).sendKeys("1001");
Thread.sleep(5000);
driver.findElement(By.id("PostalAddress_Country")).sendKeys("Australia");
//Select objSelect = new Select(null);
//new Select(driver.findElement(By.id("PostalAddress_City"))).selectByVisibleText("SYDNEY, NSW, Australia, 1001");
driver.findElement(By.id("saveClient")).click();
Thread.sleep(5000);
}
【问题讨论】:
-
您在哪一行遇到异常?
-
你为什么还要这样发送数据?这是硬编码,您应该将测试数据保存在单独的存储库中(excel、数据库),您的测试数据本质上应该是动态的。