您好,我正在使用 selenium webdriver,在运行下面的脚本时,我在脚本中突出显示的位置面临陈旧元素异常错误。
我的脚本停在那里,无法运行。
错误消息是 - 过时元素异常错误。在缓存中未找到该元素,也许该页面自查找以来已发生更改。
任何人请在这种情况下帮助我并指导我纠正此错误。
问候, 维涅什·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);
}
最佳答案
工作正常,您可能需要添加隐式等待(例如 3-5 秒),因为应用程序非常慢。
或者,在元素 .//*[@id='side-menu']/li[2]/a/span
处,您也可以执行
driver.navigate().to("http://t1hub.govreports.com.au/App/#/Clients/MyClients");
我相信您遇到问题的地方是ABN
。但是,如果引发适当的等待,效果会很好。
关于java - Selenium Webdriver 过时元素异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33937849/