Skip to content

Selenium: Issue 2383: StaleElementReferenceException : Element not found in the cache workaround

April 13, 2012

It is always frustrating  when you writing a good chunk of code and getting but from Selenium framework. Here is example of not working code that throws StaleElementReferenceException: Message: u’Element not found in the cache’ :

items = driver.find_elements_by_css_selector('a.fontSizeDefault')
for item in items: #Just for example
    # some more actions

Here is workaround for this problem:

spaceLinksCount = len(driver.find_elements_by_css_selector('a.fontSizeDefault'))

for i in range(spaceLinksCount):
    # some more actions

But it is more slower to compare with first chunk (that is not working due to Selenium: Issue 2383). More details one can find in Selenium issue tracker

From → Selenium

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: