2012-08-15 15 views
0

網頁具有嵌套的幀結構。幀FCCBMain嵌套在幀Main中。我可以訪問它這樣說:Watir-webdriver - 無法通過編號訪問嵌套幀

browser.frame(:id => "FCCBMain").frames[0] 
=> #<Watir::Frame:0x504e155578d49f34 located=false selector={:index=>0}> 
browser.frame(:id => "FCCBMain").frames[0].id 
=> "MainLeft" 

但不是這樣:

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/[email protected]/components/driver_component.js:5329:in `unknown' 
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/[email protected]/components/driver_component.js:6623:in `unknown' 
from [remote server] file:///tmp/webdriver-profile20120816-21551-1a8xyvv/extensions/[email protected]/components/command_processor.js:9924:in `unknown' 
... 

我覺得這兩種方式都非常相似。後來爲什麼不工作?

(如果有幫助,here是我工作的網頁)

回答

2

首先,我認爲你有一個錯字與「brwoser.frame」

其次,如果你要使用訪問框架您必須在路徑IE:browser.frame(:id =>「FCCBMain」)中包含所有框架和框架集。frameset.frameset.frame(:id =>「MainLeft」)。id

原因你的第二個解決方案不起作用是因爲它正在尋找框架(FCCBMain)的直接子節點的ID爲「MainLeft」。幀(FCCBMain)只有一個框架集子,並且框架集沒有ID。如果框架集的ID爲「MainLeft」並且是一個框架(不是框架集),那麼該行,browser.frame(:id =>「FCCBMain」).frame(:id =>「MainLeft」).id工作。