0

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 ?

Ishita Shah
  • 3,955
  • 2
  • 27
  • 51
  • It's nothing to do with the Action class. The element you are trying to interact with has become stale, ie. detached from the DOM. You need to make sure the element is interactable first. Perhaps post the URL to your website? – Alichino Nov 28 '18 at 12:21
  • Element is interactable with Click() method. – Ishita Shah Nov 28 '18 at 12:27
  • Hmm sorry you did say that... :) Can you copy the whole code between when you find the element and the Action? Something must be happening in between that causes the exception. – Alichino Nov 28 '18 at 12:30

2 Answers2

0

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

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();
MicMan
  • 31
  • 5