Reputation: 71
I keep receiving the stale element reference exception
when using the code below so I decided to add in a try/catch
block. I am still receiving this error. Is my try/catch
block not written properly?
it 'should test cells updated correctly', ->
try
element(By.css('#D6'))
console.log('try')
catch staleElementException
console.log('catch')
element(By.css('#D6')).click().then ->
expect(element(By.css('div.gc-formula-input')).getText()).toBe 'hello'
Upvotes: 1
Views: 181
Reputation: 708
Put the try/catch block in a loop and wait until it stops throwing the exception. Then click on the element.
This is my first time with coffeescript and protractor, so bear with me.
it 'should test cells updated correctly', ->
// Define a function to check if an element is stale
elementIsStale = (elementToCheck) ->
try
// Silently exercise the element
elementToCheck.getText
false
catch staleElementException
true
// Wait while the element is stale
while elementIsStale(element(By.css('#D6')))
// wait a moment - don't know how to do this in coffeescript
// Now we're ready to click on the element
element(By.css('#D6')).click().then ->
expect(element(By.css('div.gc-formula-input')).getText()).toBe 'hello'
Upvotes: 1