2011-07-22 38 views
0

我正在嘗試編寫一個測試,它將點擊一個描述框並鍵入一個快速描述。在Firefox 4中使用Selenium 2.0時,我使用的代碼是:Selenium 2 Webdriver無法找到xpath從Firefox 4升級到5之後的元素

 WebElement venueDescription = driver.findElement(By.xpath("//iframe[contains(@id,'Frame')]")); 

    venueDescription.sendKeys("This is a description for the Venue"); 

要做到這一點。但是,升級到Firefox 5和Selenium 2.1後,我收到「無法定位元素」錯誤。 這裏是代碼的副本。 第一個和第三個textarea被隱藏,所以我使用contains()來選擇第二個textarea。這是工作正常,直到更新。

<input id="cf_textarea1311363997499___Config" type="hidden" style="display:none" value="LinkBrowserURL=%2FCFIDE%2Fscripts%2Fajax%2FFCKeditor%2Feditor%2Ffilemanager%2Fbrowser%2Fdefault%2Fbrowser.html%3FConnector%3D..%2F..%2Fconnectors%2Fcfm%2Fconnector.cfm%26_cf_clientid%3D242D1F3D48B023DBFB61177D36938485&LinkUploadURL=%2FCFIDE%2Fscripts%2Fajax%2FFCKeditor%2Feditor%2Ffilemanager%2Fconnectors%2Fcfm%2Fupload.cfm%3F_cf_clientid%3D242D1F3D48B023DBFB61177D36938485&ImageBrowserURL=%2FCFIDE%2Fscripts%2Fajax%2FFCKeditor%2Feditor%2Ffilemanager%2Fbrowser%2Fdefault%2Fbrowser.html%3FType%3DImage%26Connec...e%3DImage%26_cf_clientid%3D242D1F3D48B023DBFB61177D36938485&FlashBrowserURL=%2FCFIDE%2Fscripts%2Fajax%2FFCKeditor%2Feditor%2Ffilemanager%2Fbrowser%2Fdefault%2Fbrowser.html%3FType%3DFlash%26Connector%3D..%2F..%2Fconnectors%2Fcfm%2Fconnector.cfm%26_cf_clientid%3D242D1F3D48B023DBFB61177D36938485&FlashUploadURL=%2FCFIDE%2Fscripts%2Fajax%2FFCKeditor%2Feditor%2Ffilemanager%2Fconnectors%2Fcfm%2Fupload.cfm%3FType%3DFlash%26_cf_clientid%3D242D1F3D48B023DBFB61177D36938485&AutoDetectLanguage=false&DefaultLanguage=en"> 
<iframe width="0" scrolling="no" height="0" frameborder="0" src="javascript:void(0)" style="position: absolute; z-index: 10000;"> 
<iframe width="0" scrolling="no" height="0" frameborder="0" src="javascript:void(0)" style="position: absolute; z-index: 10000;"> 
<iframe width="0" scrolling="no" height="0" frameborder="0" src="javascript:void(0)" style="position: absolute; z-index: 10000;"> 
<iframe width="0" scrolling="no" height="0" frameborder="0" src="javascript:void(0)" style="position: absolute; z-index: 10000;"> 
<iframe width="0" scrolling="no" height="0" frameborder="0" src="javascript:void(0)" style="position: absolute; z-index: 10000;"> 
<iframe width="0" scrolling="no" height="0" frameborder="0" src="javascript:void(0)" style="position: absolute; z-index: 10000;"> 
<iframe id="cf_textarea1311363997499___Frame" width="675" scrolling="no" height="200" frameborder="0" src="/CFIDE/scripts/ajax/FCKeditor/editor/fckeditor.html?InstanceName=cf_textarea1311363997499&Toolbar=BasicText"> 
<textarea id="cf_textarea1311363997499" name="description" style="display: none;"></textarea> 
+0

如果你想要這個回答,我建議將示例HTML修剪爲更簡單的條件。 – MarkHu

回答

0

您是否嘗試過在與之交互之前先切換到iFrame?

在網站上我測試,一切都被嵌入iFrame中之前,我可以去任何他們的元素,我必須先切換到他們,就像這樣:

driver.switchTo().defaultContent(); 
driver.switchTo().frame(driver.findElement(By.xpath("//iFrame[@id='Frame']")));