how to avoid or ignore "StaleElementReferenceError" error?

276 views
Skip to first unread message

look...@gmail.com

unread,
Dec 5, 2016, 10:52:36 PM12/5/16
to Selenium Users
Hi,

I meet the following error when i try to mouseDown and mouseUp an drop-down list option on my app. The scenario is that, a pop-up iframe will pop-up after the option is selected. The actual result is that the option is selected but the following error was threw. In this case, i want to find a way to ignore the error and continue my script.

(node:1148) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejec
tion id: 1): StaleElementReferenceError: stale element reference: element is not
 attached to the page document

I am using nodeJS and my script is something like following. And i try that i cannot select the option by using webelement.click() successfully, so i try to use ActionSequence.

        var AcS = new webdriver.ActionSequence(driver);

        driver.wait(until.elementLocated(By.css(optionCss)), 10 * globalWaitTime).then(function(){
driver.wait(until.elementIsVisible(driver.findElement(By.css(optionCss))), 10 * globalWaitTime).then(function(){
var elOption = driver.findElement(By.css(optionCss));
AcS.
mouseDown(elOption).
mouseMove(elOption).
mouseUp(elOption).
perform();
});
});

look...@gmail.com

unread,
Dec 7, 2016, 8:26:12 AM12/7/16
to Selenium Users
I got a solution... if i use "driver.actions()" directly, then there would be no such error. 

such as the following,

    driver.actions().
    mouseDown(elOption).
  mouseMove(elOption).
  mouseUp(elOption).
    perform();

Shawn McCarthy

unread,
Dec 7, 2016, 10:47:25 AM12/7/16
to Selenium Users
StaleElementReferenceError means that you get an element, and before you do the action (like click or mouseDown or whatever), the element changes. It's a timing issue, from my experience.
Reply all
Reply to author
Forward
0 new messages