在使用下面的代码时,我一直收到stale element reference exception
,因此我决定添加try/catch
块。我仍然收到此错误。我的try/catch
块是否写得不正确?
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'
答案 0 :(得分:1)
将try / catch块放入循环中并等待它停止抛出异常。然后单击元素。
这是我第一次使用coffeescript和量角器,所以请耐心等待。
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'