Skip to content

Alerts, Confirms and Prompts in Frames and iFrames

Paul-Clewell edited this page Dec 12, 2011 · 1 revision

The page-object gem provides a way to allow you to "catch" alerts, confirms and prompts, pass in information, and send it back to the browser.

With the release of version 0.5.2, page-object changed in order to properly capture information within frames and iframes, and thus it changed the way that it interacted with alerts, confirms and prompts.

To use alerts with version 0.5.2, you must place it in a function, place the button within the frame, pass the alert into a frame, and the button_element into a frame.

For example:

def function_name
    in_frame(:name => 'frame_name') do |frame|
       self.alert(frame) { button_element(:id => 'button_id', :frame => frame).click}
    end
end

To use confirms is much the same, the only exception being that you must pass in a response (either true or false, below I use false):

def function_name
    in_frame(:name => 'frame_name') do |frame|
       self.confirm(false, frame) { button_element(:id => 'button_id', :frame => frame).click}
    end
end

To use prompts is very similar to the above two, the exception being that you must pass in an answer to the prompt (here I used "Some Value":

def function_name
    in_frame(:name => 'frame_name') do |frame|
       self.prompt("Some value", frame) { button_element(:id => 'button_id', :frame => frame).click}
    end
end