staleElementReference error on action class

394 Views Asked by At

As we use action class for usually Click event. Somehow I am getting exception on each action class usage. It throws StaleElementReference exception on every action method, Not working for single instance.

Element does not able to click while Debugging also. When I replaced it by simple Click() method, It worked fine. But, I can't use click method based on some other exception dependency.

What could went wrong,

using OpenQA.Selenium.Interactions;

Actions action = new Actions(driver);
action.MoveToElement(WebElement).Click().Perform();

Am I missing something ?

2

There are 2 best solutions below

0
On

The element you are trying to access is no longer being shown in the page. The element may still be on the page but you may have navigated throughout the page after finding the element meaning that this is a new version of the element the driver is trying to access and the old one has dissappeared.

Do driver.findElement again and then use the actions move to if you are positive the element is still being shown.

0
On

You need to get the element again (if it's even clickable now).

IWebElement WebElement;
...

By byLocator = By.Id("myElementId");
WebElement = driver.FindElement(byLocator);
Actions action = new Actions(driver);
action.MoveToElement(WebElement).Click().Perform();