title: Watir/Page Object Existence Methods Timing Out
body: <p>I recently upgraded from:</p>
  
  <ul>
  <li>Page Object 1.2.2 </li>
  <li>Watir-Webdriver 0.9.9 </li>
  <li>Selenium WebDriver 2.53.0</li>
  <li>Firefox 45.8.0</li>
  </ul>
  
  <p>To:</p>
  
  <ul>
  <li>Page Object 2.2.0</li>
  <li>Watir 6.3.0</li>
  <li>Selenium-Webdriver 3.4.3</li>
  <li>Firefox 52.2.0</li>
  </ul>
  
  <p>After a little bit of pain, I've finally gotten my tests to start running! One small snag though. The methods <code>#present?</code>, <code>#exists?</code>, and <code>#visible?</code> don't return anything, they just timeout instead. Similarly, <code>#wait_until</code>, <code>x_element.when_present?</code>, and similar methods all hit the same problem!</p>
  
  <p>Here is my page object:</p>
  
  <pre><code>class LoginPage &lt; TeamConnectPage
  
    MAX_LOGIN_ATTEMPTS = 3
  
    button :ok, value: /^OK$/i
    button :submit, value: 'Login'
    button :new_session, value: 'New Session'
    link :logout, id: 'LINK_default_logout'
    span :error_message, class: 'texterror'
    text_field :username, name: 'j_username'
    text_field :password, name: 'j_password'
  
    def login_as(username)
      username = username.to_s
      do_logout if logged_in?
      attempts = 0
      try_login(username)
      while username_element.present?
        fail "#{MAX_LOGIN_ATTEMPTS} logins attempted unsuccessfully for user #{username}" if (attempts+=1) == MAX_LOGIN_ATTEMPTS
        try_login(username)
      end
      if new_session_element.present?
        new_session
        logout_element.when_present(10)
      end
    end
  
    private
  
    def try_login(username)
      self.username = username
      self.password = 'test'
      submit
      wait_for_login_submit
    end
  
    def wait_for_login_submit
      wait_until(10) { !username_element.present? || (username_element.present? &amp;&amp; username_element.value.empty?) }
      wait_until(10) { error_message_element.present? || logout_element.present? || new_session_element.present? }
    end
  
    def do_logout
      logout
    end
  
    def logged_in?
      logout_element.present?
    end
  end
  </code></pre>
  
  <p>Here's the step definition where I'm calling the page object:</p>
  
  <pre><code>def login_role role
    caps = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
    @browser ||= Watir::Browser.new(:firefox, desired_capabilities: caps)
    @browser.driver.manage.window.maximize
    @browser.goto('http://ntdmatters-it4.nwie.net/TeamConnect/login')
    @logged_in_user = User[RoleMapping[role]]
    on_page(LoginPage).login_as(@logged_in_user.userid)
  end
  </code></pre>
  
  <p>Here's my load order:</p>
  
  <pre><code>require 'pry'
  require 'active_support'
  require 'active_support/core_ext'
  require 'chronic'
  require 'page-object'
  require 'rspec'
  require 'watir'
  require 'selenium-webdriver'
  </code></pre>
  
  <p>And here's the error I'm getting:</p>
  
  <pre><code>      timed out after 30 seconds, waiting for #&lt;Watir::Anchor: located: false; {
  :id=&gt;"LINK_default_logout", :tag_name=&gt;"a"}&gt; to be located (Watir::Exception::UnknownObjectException)
        (eval):1:in `process_watir_call'
        ./features/support/env.src/pages/login_page.rb:48:in `do_logout'
        ./features/support/env.src/pages/login_page.rb:15:in `login_as'
        ./features/step_definitions/login_steps.rb:24:in `login_role'
        ./features/step_definitions/login_steps.rb:2:in `/^I login to Project
  with role (.*)$/'
  </code></pre>
  
  <p>What happens is that the script will hit that the <code>#logged_in?</code> method and just sit there. Then it will time out and give me the above error message.</p>
  
  <p>I can't help and wonder if this is some sort of configuration problem and that things just need to be loaded correctly or if there's some sort of deeper trap I have fallen into.</p>
  
  <p>EDIT:</p>
  
  <p>When I changed the Selenium logger level to 'Info', I got the following repeated for 30 seconds:</p>
  
  <pre><code>2017-07-12 12:11:21 INFO Selenium    &gt;&gt;&gt; http://127.0.0.1:4444/session/8d74a28f-
  d8fc-4db6-a851-4f238edf7d70/element | {"using":"css selector","value":"#LINK_def
  ault_logout"}
  2017-07-12 12:11:21 INFO Selenium &lt;- {"value":{"error":"no such element","messag
  e":"Unable to locate element: #LINK_default_logout","stacktrace":"stack backtrac
  e:\n   0:           0x4bd56f - &lt;no info&gt;\n   1:           0x4bdcc9 - &lt;no info&gt;\n
     2:           0x43dc4d - &lt;no info&gt;\n   3:           0x44db84 - &lt;no info&gt;\n   4
  :           0x44a1ca - &lt;no info&gt;\n   5:           0x4207bc - &lt;no info&gt;\n   6:
          0x405e47 - &lt;no info&gt;\n   7:           0x6db3d9 - &lt;no info&gt;\n   8:
      0x417847 - &lt;no info&gt;\n   9:           0x6d56d3 - &lt;no info&gt;\n  10:         0x
  776c59cd - BaseThreadInitThunk"}}
  </code></pre>
  
  <p>EDIT2: This occurs whether or not the element is actually present or not. </p>