The webpage has a nested frame structure. The frame FCCBMain is nested in frame Main. I can access it this way:
browser.frame(:id => "FCCBMain").frames[0]
=> #<Watir::Frame:0x504e155578d49f34 located=false selector={:index=>0}>
browser.frame(:id => "FCCBMain").frames[0].id
=> "MainLeft"
But not this way:
brwoser.frame(:id => "FCCBMain").frame(:id => "MainLeft").id
Selenium::WebDriver::Error::StaleElementReferenceError: Element belongs to a different frame than the current one - switch to its containing frame to use it
from [remote server] resource://fxdriver/modules/web_element_cache.js:5634:in `unknown'
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/fxdriver@googlecode.com/components/driver_component.js:5329:in `unknown'
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/fxdriver@googlecode.com/components/driver_component.js:6623:in `unknown'
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/fxdriver@googlecode.com/components/command_processor.js:9924:in `unknown'
...
I thought these two ways are very similar. Why doesn’t the later work?
(if it helps, here is the webpage I’m working on)
First I think you have a typo with “brwoser.frame”
Second if you are going to access the frames with the chain you have to include ALL frames and framesets in the path IE: browser.frame(:id => “FCCBMain”).frameset.frameset.frame(:id => “MainLeft”).id
The reason your second solution was not working is because it was looking for an immediate child of frame(FCCBMain) to have the id of “MainLeft”. Frame(FCCBMain) only has a frameset child and the frameset does not have an ID. If the frameset had an ID of “MainLeft” AND was a frame(not a frameset) then the line, browser.frame(:id => “FCCBMain”).frame(:id => “MainLeft”).id, would work.