Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 没有这样的元素时如何继续_Ruby_Selenium_Webdriver_Element - Fatal编程技术网

Ruby 没有这样的元素时如何继续

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

我想验证对象是否存在。在下面的示例中,实际元素: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 = 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