2011-08-12 30 views
2

我試圖自動化一個簡單的頁面,該頁面有一個加載內部iFrame的colorbox。每當我在Selenium中記錄測試時,它都會捕獲iframe。但是當我重新運行測試時,它無法抓取內部的iframe。我看着它,你會看到這樣的代碼:Colorbox Iframe名稱不斷變化,所以我不能用Selenium選擇框架

命令:selectFrame 目標:iframe_1313186641607 值:(空)

我去Firefox和檢查元素,我看到:

<div> 
<div id="cboxMiddleLeft" style="float: left; height: 558px;"></div> 
<div id="cboxContent" style="float: left; width: 698px; height: 558px;"> 
<div id="cboxLoadedContent" style="display: block; width: 698px; overflow: auto; height: 530px;"> 
<iframe id="cboxIframe" frameborder="0" src="SelectCourseOptions.aspx?courseno=111&subject=ACC&term=Fall 2010" name="iframe_1313186641607"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<body style="background-color: White"> 
<form id="form1" action="SelectCourseOptions.aspx?courseno=111&subject=ACC&term=Fall+2010" method="post" name="form1"> 
<div> 

所以你可以看到它匹配iframe的「名稱」。然後,我會去重新運行測試,它無法選擇的iframe,我會再次檢查元素,看到以下內容:

<div> 
<div id="cboxMiddleLeft" style="float: left; height: 558px;"></div> 
<div id="cboxContent" style="float: left; width: 698px; height: 558px;"> 
<div id="cboxLoadedContent" style="display: block; width: 698px; overflow: auto; height: 530px;"> 
<iframe id="cboxIframe" frameborder="0" src="SelectCourseOptions.aspx?courseno=111&subject=ACC&term=Fall 2010" name="iframe_1313186725931"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<body style="background-color: White"> 
<form id="form1" action="SelectCourseOptions.aspx?courseno=111&subject=ACC&term=Fall+2010" method="post" name="form1"> 
<div> 

現在你可以看到的iframe名:

NAME =「iframe_1313186725931」

這是第一次不同的,當我記錄的測試:

NAME =「iframe_1313186641607」

只是爲了好玩我關上了顏色框的d重新打開並且名稱再次改變。我該如何解決這個問題?看來colorbox每次都會生成一個動態名稱,所以我不能在Selenium中選擇它?

感謝您的幫助。

回答

1

我想出瞭如何做到這一點,我只是一個Selenium n00b。我需要通過id而不是名稱標籤來選擇colorbox。就像這樣:

命令:selectFrame目標:ID = cboxIframe值:(空)

這一工程!

0

萬一別人有與動態I幀類似的問題時,請注意我用的php硒webdriver的 「臉譜」:

$iFrame = $webDriver->findElement(WebDriverBy::xpath('//iframe[@id="cboxIframe"]')); 

$iFrame = $webDriver>findElement(WebDriverBy::xpath('//iframe[@class="cboxIframe"]')); 

$iFrame = $webDriver->findElement(WebDriverBy::xpath('//iframe[@name="cboxIframe"]')); 

最後將焦點轉移到iFrame

$webDriver->switchTo()->frame($iFrame); 
相關問題