I have a selenium test in Java and I am doing some assertions like that:
assertFalse(isElementPresent(By.xpath("//td[2]/div")));
private boolean isElementPresent(By by) {
try { driver.findElement(by); return true; }
catch (NoSuchElementException e) {
return false; }
It´s the standard method Selenium is generating when export from IDE to Java Webdriver.
(Yes I want to assert that this element is not present)
I always get errors when I am testing at this above code line Error: stale element reference: element is not attached to the DOM
But when I put a thread.sleep in front of that step it works. The fact I don´t get is that it is enough to wait 1 milli sec. Is it typical to wait before an assertion? Is there another way to solve this? (Implicit wait is not helping here) Greetings from Germany!
isElementPresent()
– Urinary