Closed curtisy1 closed 6 years ago
Duplicate of #4724
Specifically, this is the intended behavior. https://github.com/SeleniumHQ/selenium/issues/4724#issuecomment-330862710
@lmtierney It's actually a completely different issue. What I described in the one you referred to is that the same Action can only keep its 'state' and do the same action over and over again. (as an example, using a click.SendKeys(Keys.Enter).Build().Perform();
and a click.SendKeys(Keys.Delete).Build().Perform();
after another would reproduce #4724.
What I'm describing here is that by making use of that exact feature by calling click.Click(Element1).Build().Perform();
and then click.Click(Element2).Build().Perform();
the click Action should remember only the Click() event (as it's the same action sequence). This is the case with the cutpaste Action (or rather Contextclick), so even if it would be a duplicate, something on this is inconsisten it seems.
@curtisy1 I'm sorry, you're mistaken. It is a duplicate. The action sequence doesn't just consist of the actions added to it, but also the specific element references used to create the action sequence. In effect, what you've asked the click
Action to do is the following:
foo
(which is described by popup[0]
)Then, at some later time, since the click
action is not reset, you ask it to do the following:
foo
(which is described by the original popup[0]
, and is now likely stale)bar
(which is described by the new popup[0]
)This is exactly what's described by the other element. Since the Actions
class is lightweight to create, you should create a new one for the second click.
@jimevans Thanks for the detailed explanation. However I'm still a bit short on why the cutpaste Action in my code snippet works fine. Any idea why this doesn't produce a StaleElementReference Exception?
Because the elements the cutpaste
action refers to (and it refers to multiple elements at the end, so it right-clicks on two elements the second time Perform
is called), aren’t stale. The elements referred to in the DOM haven’t been removed and replaced, as they have on the pop up menu.
and it refers to multiple elements at the end, so it right-clicks on two elements the second time Perform is called
Ohh that makes a lot more sense.
Thanks for taking the time to explain this :)
Meta -
OS: Windows 10, Fall update Selenium Version: .NET 3.7.0 Browser: Firefox
Browser Version: 59.0a1 (2017-11-16) (64-Bit)
Expected Behavior -
Actions should be capable of performing actions to different elements in one go, as documented in the Python reference here.
Actual Behavior -
Calling Click() with different elements results in a StaleElementReference Exception
Steps to reproduce -
Note: I didn't test if this example works as well, but it generally should. I simply changed my selectors and adjusted them to match those of the test case.
For an example that should be able to reproduce this, see here.