Capturing Error From Appium

I'm running RubyMine 8.0.3, Ruby 2.2.1, and Appium 8.0.2 on a MacBook to control an app on an Android tablet.  Appium is used to  inspect the XML for the screens.

The Appium command find_element(:xpath, '//path1/path2/element') throws an error NoSuchElementError if the element is not found and then stops the test.

I want to be able to capture the Appium error and not have the test fail automatically.  For example, a "Next Page" button would be "missing" on the last page in a series, but checking for it in Appium would crash the test.

Here's what I've tried so far (which didn't work):

class MissingElement < StandardError



def unknown_element

 element = find_element(:xpath, '//android.webkit.WebView[1]/android.woidget.Button[6]')

if element.class = nil.class

raise MissingElemenet,'elemenet does not exist'




Then /^I try to find a missing element: (.*?).$/ do |arg1|

puts 'Unknown Element #{arg1}'



rescue MissingElement => error

puts 'Error #{error.message}'




Thanks in  advance.

Please sign in to leave a comment.