【发布时间】:2015-07-02 11:21:05
【问题描述】:
当我的代码遇到select_to_city(to),
我猜它会被Selenium::WebDriver::Error打破
但它并没有停止救援为什么?
class Tiger123 < ClassTemplate
def form_action(from, to, flight_date)
begin
select_to_city(to)
select_depart_date(flight_date)
rescue Selenium::WebDriver::Error => e
binding.pry
rescue Exception => e
binding.pry
end
end
def select_to_city(to)
@driver.find_element(:id, "selDestPicker").click
@driver.find_element(:id, to).click
end
更新
最后我在 select_to_city 函数中添加了rescue
它确实奏效了。我不明白为什么它没有在form_action 方法中进行救援
def select_to_city(to)
begin
@driver.find_element(:id, "selDestPicker").click
@driver.find_element(:id, to).click
rescue Exception => e
binding.pry
end
end
【问题讨论】:
-
你猜它会坏掉吗?可以?如果它确实抛出了什么样的异常,因为无论如何它都会被
Exception救出,除非它实际上并没有引发异常。 -
@engineersmnky 我确信救援根本不起作用。因为我停在 select_to_city(to) 之前的第一个断点,然后是
continue,然后它没有停在select_depart_date(flight_date)之后的breakpoint处
标签: ruby selenium-webdriver rescue