title: Ruby Selenium begin rescue
body: <p>I use Cucumber with Ruby and Selenium. 
  Here is scenario where I need to check that element is not on the page
  When I do such within Cucumber step</p>
  
  <pre><code>    Step file:
      begin
       expect(checkout_page.city_acctdetails.displayed?).to eql false
      rescue Selenium::WebDriver::Error::NoSuchElementError
       puts "City dropdown is not present"
       false
      end
  </code></pre>
  
  <p>it works like a charm.
  When I try to do something like by putting as method in another file/helper</p>
  
  <pre><code> RubyHelper.rb file
     def self.not_present(locator)
      begin
        locator.displayed?
      rescue Selenium::WebDriver::Error::NoSuchElementError
        puts "Not present"
        false
      end
    end
  </code></pre>
  
  <p>so when I change in Cucumber Step file</p>
  
  <pre><code>RubyHelper.not_present(checkout_page.city_acctdetails)
  </code></pre>
  
  <p>I get error:
  Unable to locate element: {} (Selenium::WebDriver::Error::NoSuchElementError)</p>
  
  <p>Require statements:</p>
  
  <pre><code>  #BDD framework that makes feature files running
  require 'cucumber'
  
  #Control remote browsers
  require 'selenium-webdriver'
  
  #Run tests in parallel
  require 'parallel_tests'
  
  #Use expect().to for verifying result
  require 'rspec'
  
  #Key value format for storing text data
  require 'yaml'
  </code></pre>