why am I getting StaleElementReferenceException?

287 views
Skip to first unread message

Bryan Oakley

unread,
Aug 16, 2011, 4:40:52 PM8/16/11
to selenium-users
I'm using the webdriver python bindings to connect to a remote
webdriver. I'm getting a StaleElementReferenceException and I don't
understand why. I'm getting it when I call find_elements_by_tag_name
after clicking on a link that causes a new page to load.

I understand why I would get this if I found an element, refreshed the
page, then tried to use the element. In this case, however, I'm
waiting for the page to load and then simply trying to get (but not
yet use) an element.

I'm using selenium-server-standalone-2.4.0.jar and the 2.4.0 python
bindings with python 2.7

Here's the relevant bits of my code:

driver = webdriver.Remote(
command_executor = SeHUB,
desired_capabilities = {
"browserName": "internet explorer",
}
)
driver.implicitly_wait(10)
driver.get(ROOT)

## proof that find_elements_by_tag_name isn't fundamentally
## busted
elements = driver.find_elements_by_tag_name("div")
print "elements", elements

## log in to the application
element = driver.find_element_by_id(USERNAME_FIELD)
element.send_keys(USERNAME)
element = driver.find_element_by_id(PASSWORD_FIELD)
element.send_keys(PASSWORD)
button = driver.find_element_by_id(LOGIN_BUTTON)
button.click()

## artificial time to wait for the page to load
time.sleep(5)

## same call as before, but this throws the exception
## StaleElementReferenceException
elements = driver.find_elements_by_tag_name("div")
print "elements", elements

driver.quit()
print "success!"

Luke Inman-Semerau

unread,
Aug 16, 2011, 5:27:42 PM8/16/11
to seleniu...@googlegroups.com
You need to downgrade the server to 2.3, there's a bug in 2.4.  You can leave the python code for 2.4, just use server-standalone version 2.3 (and only remote calls, if you use firefox or ie direct, then you'll need to replace the xpi and dll respectively in your python site-packages/selenium directory with the ones that are in the jar).


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Bryan Oakley

unread,
Aug 16, 2011, 5:39:40 PM8/16/11
to seleniu...@googlegroups.com
Thank you for the quick reply. And sure enough, downgrading solved my problem.
Reply all
Reply to author
Forward
0 new messages