Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Proper handling of alerts and prompts is still <a href="http://code.google.com/p/selenium/issues/detail?id=27" rel="nofollow noreferrer">being worked on</a> in WebDriver, but a common workaround is to overwrite the window functions using execute_script(), i.e.</p> <pre><code>browser.execute_script("window.alert = function(msg) { window.lastAlert = msg; }") browser.button(:id =&gt; "trigger-alert").click browser.execute_script("return window.lastAlert") #=&gt; "the message" </code></pre> <p>Since I'd like to avoid a bunch of monkey patches floating around (a common problem in the Watir community), I've added some <a href="http://github.com/jarib/watir-webdriver/commit/8fd5fd2a35c252fe4b72d401a655b01abb16b916" rel="nofollow noreferrer">helper methods</a> as an optional require - after the next release you should be able to do:</p> <pre><code>require "watir-webdriver/extensions/alerts" browser.alert do browser.button(:id =&gt; "alert").click end #=&gt; "the alert message" browser.confirm(true) do browser.button(:id =&gt; "confirm").click end #=&gt; "the confirm message" browser.prompt("returned value") do browser.button(:id =&gt; "prompt").click end #=&gt; { :message =&gt; "foo", :default =&gt; "bar" } </code></pre> <p>Note that this is temporary and the API may be removed in the future when the issue is resolved in WebDriver.</p> <p>UPDATE:</p> <p>Proper alert handling is now implemented. The above example would now be done like this:</p> <pre><code>browser.button(:id =&gt; "alert").click browser.alert.ok browser.button(:id =&gt; "confirm").click browser.alert.ok # or browser.alert.close browser.button(:id =&gt; "prompt").click alert = browser.alert alert.text #=&gt; "foo" alert.ok </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload