title: How to get a Selenium/Ruby bot to wait before performing an action?
body: <p>I'm building a Selenium/Ruby web bot that clicks on elements. The problem is, sometimes there isn't enough time for the page to load before the bot decides it can't find the element.</p>
  
  <p>What's the Ruby way to get Selenium to wait before performing an action? I would prefer explicit waiting, but I'm fine with implicit waiting too.</p>
  
  <hr>
  
  <p>I tried to use the <code>wait.until</code> method:</p>
  
  <pre><code>require "selenium-webdriver"
  require "nokogiri"
  driver = Selenium::WebDriver.for :chrome
  wait = Selenium::WebDriver::Wait.new(:timeout =&gt; 15)
  driver.navigate.to "http://google.com"
  driver.wait.until.find_element(:class, "gb_P").click
  </code></pre>
  
  <p>But I'm getting the following error:</p>
  
  <pre><code>Undefined method 'wait' for &lt;Selenium::WebDriver&gt;
  </code></pre>
  
  <hr>
  
  <p>I also tried:</p>
  
  <pre><code>require "watir-webdriver/wait"
  ...
  driver.find_element(:class, "gb_P").wait_until.click
  </code></pre>
  
  <p>but that's also giving me an undefined method error:</p>
  
  <pre><code>undefined method `when_present' for #&lt;Selenium::WebDriver...&gt;
  </code></pre>