使用ruby webdriver获取文件结束(EOFError)

时间:2014-06-23 01:53:47

标签: ruby watir-webdriver selenium-chromedriver

我的一些测试通过一次,然后失败并显示“文件结束(EOFError)”。无法弄清楚导致此一致性问题的原因。填写表格时有时会失败。其他时候单击按钮时会失败。

使用以下内容: OSX 10.9.3 Watir-webdriver 0.6.10 Ruby 1.9.3 Chrome 35.0 Chromedriver ChromeDriver v2.10

1 个答案:

答案 0 :(得分:-3)

不确定问题是什么,但解决此错误的一个简单方法是使用导致此错误的代码周围的Begin / Rescue语句(检查终端输出所说的导致错误的行号)

例如:

browser.close #This is the line giving the EOFError

执行以下操作:

begin
    browser.close #if there is an error: jump to the rescue statement
rescue
    #don't put any code in the rescue statement (ignore the error)
end
#rest of code

begin / rescue语句的工作方式是,如果begin语句中的代码导致错误,它将运行rescue语句中的代码。在这种情况下,由于救援语句中没有任何代码,它只会忽略错误并继续使用其余代码。