Selenium: Unterschied zwischen den Versionen
Aus Peter Jauernig Wiki
(Die Seite wurde neu angelegt: „ Code: public static void moveBeginMonthForward (int times) throws Exception{ System.out.println(times); //Select Month // We…“) |
|||
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
+ | == StaleElementReferenceException == | ||
Code: | Code: | ||
− | + | <pre> | |
public static void moveBeginMonthForward (int times) throws Exception{ | public static void moveBeginMonthForward (int times) throws Exception{ | ||
− | |||
− | |||
− | |||
WebElement fw = driver.findElement(By.linkText("Next")); | WebElement fw = driver.findElement(By.linkText("Next")); | ||
for(int i=0; i<times; i++) | for(int i=0; i<times; i++) | ||
{ | { | ||
− | |||
fw.click(); | fw.click(); | ||
− | |||
Thread.sleep(1000); | Thread.sleep(1000); | ||
} | } | ||
} | } | ||
+ | |||
+ | </pre> | ||
+ | |||
Error: org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM | Error: org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM | ||
A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated. | A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated. | ||
+ | |||
+ | |||
+ | Solution: | ||
+ | |||
+ | <pre> | ||
+ | public static void moveBeginMonthForward (int times) throws Exception{ | ||
+ | |||
+ | |||
+ | WebElement fw = driver.findElement(By.linkText("Next")); | ||
+ | |||
+ | for(int i=0; i<times; i++) | ||
+ | { | ||
+ | fw = driver.findElement(By.linkText("Next")); | ||
+ | fw.click(); | ||
+ | Thread.sleep(1000); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </pre> |
Aktuelle Version vom 31. März 2015, 10:01 Uhr
StaleElementReferenceException
Code:
public static void moveBeginMonthForward (int times) throws Exception{ WebElement fw = driver.findElement(By.linkText("Next")); for(int i=0; i<times; i++) { fw.click(); Thread.sleep(1000); } }
Error: org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
A StaleElementException is thrown when the element you were interacting is destroyed and then recreated. Most complex web pages these days will move things about on the fly as the user interacts with it and this requires elements in the DOM to be destroyed and recreated.
Solution:
public static void moveBeginMonthForward (int times) throws Exception{ WebElement fw = driver.findElement(By.linkText("Next")); for(int i=0; i<times; i++) { fw = driver.findElement(By.linkText("Next")); fw.click(); Thread.sleep(1000); } }