2013-04-16 75 views
15

以下處理iframe是HTML代碼..與水豚紅寶石

<iframe id="I0_1366100881331" frameborder="0" width="100%"> 
<div class="ZRa"> 
<span id="button" class="hAa Qo Bg" tabindex="0" role="button" title="" aria-  label="Click here to publicly +1 this." aria-pressed="false"> 
</div> 
</iframe>  

在上述情況下,我想切換到IFRAME(IFRAME ID =「I0_1366100881331」)來執行關於本SPAN一些動作在那個IFRAME中。我曾嘗試與大多數的情況,但沒有任何結果:(......任何一個請幫助

我只使用水豚紅寶石想要黃瓜解..

注:我試着用下面的代碼,但沒有。結果

page.driver.browser.switch_to.frame 「I0_1366100881331」

+0

可能重複:http://stackoverflow.com/questions/11909149/how-can-i-switch-between-two-frames-with-capybara –

回答

11

我想你可以嘗試使用方法:

within_frame 'id' do 
    <code for dealing with iframe entries> 
end 
+1

'身份證'不是靜態的。它每次都在改變(頁面刷新),然後我們如何使用'id'來處理iframe。你能建議嗎? –

+0

舊帖子,但您必須能夠以某種方式獲得框架的ID,因爲您在上面發佈了示例代碼。 – Hannele

25
within_frame(find('<css rule>')) do 
    <code for dealing with iframe entries> 
end 
+0

這對我很好,因爲它使用'查找'水豚將等待框架出現在頁面上,如果有必要。 – user01380121

0

能有這樣的代碼:

withinframe((:xpath,"//div")) do 
#code 
end 
+0

請解釋你的代碼 – quinz