1

我在使用下面的代码时不断收到,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'
4

1 回答 1

1

将 try/catch 块放入循环中并等待它停止抛出异常。然后点击元素。

这是我第一次使用咖啡脚本和量角器,所以请多多包涵。

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'
于 2015-01-28T18:20:12.187 回答