Switching To Frames in Watir-WebDriver

1,702 views
Skip to first unread message

Jeff Nyman

unread,
Oct 6, 2011, 9:17:09 AM10/6/11
to Watir General
I just wanted to check if it's a known issue that switchTo.frame does
not appear to work with Watir-WebDriver. This does appear to work with
Selenium-WebDriver.

Here's the command I try in Selenium that does work:

@browser.switch_to.frame("ModalDialogContent")

I try a slightly modified verison of the command for Watir:

@browser.driver.switch_to.frame("ModalDialogContent")

This does not seem to work at all.

Here "ModalDialogContent" is the name of a frame within the browser
window when my application starts up. I'm early enough in framework
design that I can switch to Selenium if need be but I wanted to make
sure I was doing this correctly in Watir before I did so.

Any thoughts or suggetsions are most welcome.

- Jeff

Jari Bakken

unread,
Oct 6, 2011, 9:50:35 AM10/6/11
to watir-...@googlegroups.com
Watir has its own API for dealing with frames:

  @browser.frame(:id => "ModalDialogContent").button.click

If you reach into the WebDriver API and switch "manually", watir-webdriver will get confused.

Jari

Jeff Nyman

unread,
Oct 6, 2011, 10:04:21 AM10/6/11
to Watir General
Jari: Thanks for the reply.

So it sounds like with Watir I'll have to preface all actions with
that frame bit. For example, I would have to use this:

When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
@browser.frame(:id => "ModalDialogContent").text_field(:name,
field).when_present.set(value)
end

It doesn't look like you can just switch to the frame for a series of
commands, as you can with Selenium. The reason this might be a concern
is because sometimes the commands I execute are the same commands, but
under a different frame. However, I guess I can solve that by passing
in the name of the frame to a common method behind the scenes.

- Jeff

Chuck van der Linden

unread,
Oct 6, 2011, 11:23:01 PM10/6/11
to Watir General
Well you can switch in the sense that you can create an object that
represents the current contents of the frame. (although I think
potentially you might have to 'refresh' it if the content of the frame
is updated.

frame1 = @browser.frame(:id => "ModalDialogContent")
frame1.text_field(:name, field).set(value)

if you have to do a lot of operations within the frame it can save a
little bit if typing.

--Chuck (frames are evil, and like IE6 should die) v
Reply all
Reply to author
Forward
0 new messages