Ruby 没有这样的元素时如何继续
我想验证对象是否存在。在下面的示例中,实际元素:id是“all tab”,我将其设置为“all2 tab”,以查看是否会显示失败的通知。但是,我收到一个No-this元素错误,脚本停止 顺便说一句,我用的是ruby …response.rb:51:在'assert_ok'中:找不到id==alll tab的元素(Selenium::WebDriver::Error::NoSuchElementError) 谢谢,Ruby 没有这样的元素时如何继续,ruby,selenium,webdriver,element,Ruby,Selenium,Webdriver,Element,我想验证对象是否存在。在下面的示例中,实际元素:id是“all tab”,我将其设置为“all2 tab”,以查看是否会显示失败的通知。但是,我收到一个No-this元素错误,脚本停止 顺便说一句,我用的是ruby …response.rb:51:在'assert_ok'中:找不到id==alll tab的元素(Selenium::WebDriver::Error::NoSuchElementError) 谢谢, Scott您可以使用begin和rescue: begin option
Scott您可以使用
begin
和rescue
:
begin
option = driver.find_element(:id,"all2-tab").displayed? #exists?
if option == true
puts"View All Events Tab Exists: PASS"
else
puts"!!FAILED View All Events Tab Does not Exists"
end
rescue
puts"Element does not exist"
end
将代码包装到异常处理程序中,如
begin
# something which might raise an exception
rescue ExceptionClass => some_variable
end
谢谢你,理查德。我看到一些讨论救援的帖子,但我不知道它在说什么。
begin
# something which might raise an exception
rescue ExceptionClass => some_variable
end