Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:33:16+00:00 2026-06-16T00:33:16+00:00

Using ruby’s Watir gem, I’m trying to click a button that opens a javascript

  • 0

Using ruby’s Watir gem, I’m trying to click a button that opens a javascript popup, then click ‘ok’ on the popup and I can’t seem to do that. The button is in a frame in a frame. I have searched extensively and read the Watir wiki entry about javascript popups but nothing works.
I think this is because execute_script and click_no_wait are not working as expected.
For example, the following commands:

    @browser.execute_script('window.alert = function() {}')
    @browser.execute_script('alert("hello")')

create a javascript popup that says “hello” instead of the expected behavior of not doing anything.
The command:

    @browser.button(:value, 'Submit').click

Clicks the button which creates a javascript popup. The script then hangs until I manually click ‘ok’ on the popup.
The command:

    @browser.button(:value, 'Submit').click_no_wait

Does not click the button (or it does click the button and doesn’t trigger the onclick event).
I have also tried:

    Timeout::timeout(1) { @browser.button(:value, 'Submit').click }

and

    Thread.new { @browser.button(:value, 'Submit').click }

But Timeout never throws an exception, causing ruby to hang until I manually click ‘ok’ on the popup, and Watir doesn’t click when I run it in a new thread.

Would anyone be able to help or offer a solution?

Edit: The problem is that after @browser.button.click, the script hangs until the popup closes. @browser.alert.ok successfully closes the popup, but the script cannot execute @browser.alert.ok after the button is clicked because it hangs until the popup is closed. This catch-22 is supposed to be solved by click_no_wait, but click_no_wait is not clicking.

System information:
Windows 7 Enterprise 64 Bit
Internet Explorer Version 9.0.12
watir-4.0.2-x86-mingw32
ruby 1.9.3p286 (2012-10-12) [i386-mingw32]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:33:17+00:00Added an answer on June 16, 2026 at 12:33 am

    There is an alert api (watir-classic and watir-webdriver) that you can use to interact with the javascript popup.

    Try closing the popup using:

    @browser.alert.ok
    

    Update – Workaround:

    This appears to be a bug with using Element#click_no_wait for elements in a frame. I have updated Issue 45 and will try to submit a patch.

    In the mean time, adding the following monkey patch at the start of your script should solve the issue (ie the click_no_wait should not wait):

    require 'watir-classic'
    
    Watir::IE.new(true)
    module Watir
        class Frame
            def attach_command
                tag_name = @specifiers[:tag_name].join("' << '")
                @container.page_container.attach_command + ".frame(:tag_name => Array.new << '#{tag_name}', :unique_number => #{unique_number})"
            end
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Ruby's ri tool can I get a list of classes that implement the
Using Ruby, I'm trying to parse some documentation in which I need to split
Using Ruby on Rails. I'm trying to sort a query by number (saved as
Using Ruby (newb) and Regex, I'm trying to parse the street number from the
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
Using Ruby on Rails, if I do a gem help install a part of
Using Ruby on Rails, how can I achieve a polymorphic has_many relationship where the
Using Ruby, how can I use a single regex to match all occurrences of
Using Ruby, how can I perform background and foreground text colorization for output in
Using Ruby DBI, how can I check if a record set is empty? (without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.