Den Silver
Den Silver

Reputation: 321

Watir: How I can click button in IE popup windows

I have a customized popup IE window where there are buttons included into iframe. I can't click on any button in it. I know how to work with iframes, but I can't switch to this window. Window has title and URL.

I wrote this method:

  def confirm_ok
    self.in_iframe(:id => 'frmMain') do |frame|
      self.button_element(:id => 'btnOK', :frame => frame).click
    end
  end

But I get this error:

Watir::Exception::UnknownFrameException: unable to locate iframe using {:id=>"frmMain", :tag_name=>"iframe"}

I use Watir, PageObject. And run scenarios under IE.

Watir's method doesn't work:

browser.window(:title => "annoying popup").use do
  browser.button(:id => "close").click
end

I get error

NoMethodError: undefined method `window' for #<PA_Main:0x33f6780>

Upvotes: 0

Views: 781

Answers (1)

titusfortner
titusfortner

Reputation: 4194

As best as I can tell you have two separate issues.

Firstly, I have no idea how you set your browser variable to a page object instance. The Page Object Module definitely sets browser as a readable attribute.

So if the code is within a class that has import PageObject, you should be able to do browser.window(...) just fine.

If you are using the code outside of such a class, you need to make sure that you are in a scope that has access to the Watir::Browser instance. If you have a page object defined, you can use it like: my_page_object.browser.window(...)

Secondly - based on what you are describing, the iframe usage has to be combined with the window usage:

browser.window(title: "annoying popup") do browser.iframe(id: 'frmMain').button(id: "close").click end

Upvotes: 1

Related Questions