title: How do you accept a javascript alert while using Ruby in Selenium WebDriver
body: <p>I'm attempting to click OK in a JavaScript alert that pops-up to delete an element on the page. I have the following:</p>
  
  <pre><code>assert element_present?(:css, "#add_foods_1 &gt; table &gt; tbody &gt; tr &gt; td.cf.cc2 &gt; a.track_remove")
  @driver.find_element(:css, "#add_foods_1 &gt; table &gt; tbody &gt; tr &gt; td.cf.cc2 &gt; a.track_remove").click
  assert_equal "This will delete this food from your foods eaten today.  Click OK to continue or Cancel to return.", close_alert_and_get_its_text() 
  </code></pre>
  
  <p>And the defining code to call the <code>close_alert_and_get_its_text()</code> reads:</p>
  
  <pre><code>def close_alert_and_get_its_text(how, what)
    alert = @driver.switch_to().alert()
    alert_text = alert.text
    if (@accept_next_alert) then
      alert.accept()
    else
      alert.dismiss()
    end
    alert_text
    ensure
      @accept_next_alert = true
    end
  </code></pre>
  
  <p>I am confused on how to get tot he point of just clicking OK to close the alert. There is an OK and a Cancel on the alert.</p>