2013-07-18 102 views
0

我有一個使用WebObjects構建的動態Web應用程序。有一個鏈接,我的測試代碼試圖找到。我在找到它之前做了一個getPageSource(),並且在下面。Selenium找到一個標籤,但點擊()不起作用?

我找到了標籤成功。然後我點擊它。什麼都沒發生。我正在尋找下一頁的標籤沒有找到。

那麼,一個標籤怎麼樣可以使它不響應點擊?沒有附加js。它在一個範圍內並圍繞着一個圖像,但僅此而已。

當測試代碼執行完畢後,我可以手動點擊鏈接,然後看到下一頁。最近怎麼樣?有任何想法嗎?

[java] [1374173126242]: Going to Schedule page 
[java] [1374173126260]: 
[java] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
[java] <html xmlns="http://www.w3.org/1999/xhtml"><head> 
[java]  <meta content="text/html; charset=utf-8" http-equiv="content-type" /> 
[java]  <meta content="COM" name="keywords" /> 
[java]  <title>APP!</title> 
[java]  <link href="/cgi-bin/WebObjects/APP.woa/_wr_/wodata=/Users/ME/Projects/APP/WebServerResources/APP/login.css" type="text/css" rel="stylesheet" /> 
[java] 
[java]  <link href="/cgi-bin/WebObjects/APP.woa/_wr_/wodata=/Users/ME/Projects/APP/WebServerResources/APP/APP.css" type="text/css" rel="stylesheet" /> 
[java] 
[java] </head> 
[java] <body> 
[java]  
[java]  (some bits removed . . .) 
[java]  <div id="landing_page_main" class="welcomeBox"> 
[java]  <div class="main_cont"> 
[java]   <div class="logo"><img src="/cgi-bin/WebObjects/APP.woa/_wr_/wodata=/Users/ME/Projects/APP/WebServerResources/APP/APP-live.png" alt="APP LIVE" /></div> 
[java]   <div class="table"> 
[java]   <table width="100%" cellspacing="0" cellpadding="0" border="0"> 
[java]    <tbody><tr> 
[java]    <td valign="middle" align="center"> 
[java]     <span title="Access My Schedule"><a name="19" class="access_my_schedule_link" href="/cgi-bin/WebObjects/APP.woa/wo/Tbrd5n8SsAGIL22d7hkPCM/2.19"><img width="74" border="0" height="64" src="/cgi-bin/WebObjects/APP.woa/_wr_/wodata=/Users/ME/Projects/APP/WebServerResources/APP/arrowRight.png" ismap="ismap" /></a></span> 
[java]    </td> 
[java]    </tr> 
[java]   </tbody></table> 
[java]   </div> 
[java]  </div> 
[java]  </div> 
[java] 
[java] </body></html> 
[java] [1374173126320]: found element: 
[java]  [[FirefoxDriver: firefox on MAC (7ac7e5e2-d4e2-334b-9d99-2e6ddb7b7439)] -> class name: access_my_schedule_link] 
[java] [1374173126332]: element enabled? true 
[java] [1374173126342]: element selected? false 
[java] [1374173126362]: element displayed? true 
[java] [1374173126389]: element location: (620, 265) 
[java] [1374173126404]: element tagName: a 
[java] [1374173126431]: element text: 
[java] Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for [email protected] 
[java] Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32' 
[java] System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.6.8', java.version: '1.6.0_51' 
[java] Driver info: driver.version: APPLiveDriver 
[java]  at org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259) 
[java]  at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:228) 
[java]  at APPLiveDriver.scheduleAndBack(Unknown Source) 
[java]  at APPLiveDriver.main(Unknown Source) 
[java] Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"class name","selector":"breadcrumb_home_link"} 
[java] Command duration or timeout: 9 milliseconds 
[java] For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
[java] Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32' 
[java] System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.6.8', java.version: '1.6.0_51' 
[java] Session ID: 7ac7e5e2-d4e2-334b-9d99-2e6ddb7b7439 
[java] Driver info: org.openqa.selenium.firefox.FirefoxDriver 
[java] Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=21.0, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}] 
[java]  at sun.reflect.GeneratedConstructorAccessor14.newInstance(Unknown Source) 
[java]  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
[java]  at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
[java]  at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:191) 
[java]  at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) 
[java]  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) 
[java]  at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307) 
[java]  at org.openqa.selenium.remote.RemoteWebDriver.findElementByClassName(RemoteWebDriver.java:388) 
[java]  at org.openqa.selenium.By$ByClassName.findElement(By.java:371) 
[java]  at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299) 
[java]  at APPLiveDriver$4.apply(Unknown Source) 
[java]  at APPLiveDriver$4.apply(Unknown Source) 
[java]  at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208) 
[java]  ... 2 more 
[java] Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"class name","selector":"breadcrumb_home_link"} 
[java] Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:33:32' 
[java] System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.6.8', java.version: '1.6.0_51' 
[java] Driver info: driver.version: unknown 
[java]  at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///var/folders/oZ/oZFKAiJ8FC80oMT1b--WME+++TQ/-Tmp-/anonymous4201752404452189319webdriver-profile/extensions/[email protected]/components/driver_component.js:8444) 
[java]  at <anonymous class>.FirefoxDriver.prototype.findElement(file:///var/folders/oZ/oZFKAiJ8FC80oMT1b--WME+++TQ/-Tmp-/anonymous4201752404452189319webdriver-profile/extensions/[email protected]/components/driver_component.js:8453) 
[java]  at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///var/folders/oZ/oZFKAiJ8FC80oMT1b--WME+++TQ/-Tmp-/anonymous4201752404452189319webdriver-profile/extensions/[email protected]/components/command_processor.js:10456) 
[java]  at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///var/folders/oZ/oZFKAiJ8FC80oMT1b--WME+++TQ/-Tmp-/anonymous4201752404452189319webdriver-profile/extensions/[email protected]/components/command_processor.js:10461) 
[java]  at <anonymous class>.DelayedCommand.prototype.execute/<(file:///var/folders/oZ/oZFKAiJ8FC80oMT1b--WME+++TQ/-Tmp-/anonymous4201752404452189319webdriver-profile/extensions/[email protected]/components/command_processor.js:10401) 
+0

也許是一個提示。如果我等待一秒鐘並在相同的WebElement實例上調用click(),則會得到一個org.openqa.selenium.StaleElementReferenceException。但是我可以成功地重新找到元素(它不存在於目標頁面上)並單擊(),但仍然沒有效果。嗯.... –

回答

0

看來Selenium webDriver找不到元素,請嘗試通過xpath進行搜索。如果你提供html源代碼(它可以從firebug複製)也是很好的。 更新:感謝回覆。代碼中的類名稱爲「breadcrump_home_link」,但測試中的類名稱不同:「access_my_schedule_link」。

+0

getPageSource()獲得了頁面源代碼。因此,這是上次加載的頁面的頁面源。它在上面。 –

+0

查看包含以下內容的位:

+0

是的,您是對的。我在與類「access_my_schedule_link」具有鏈接的頁面上。我找到了該鏈接並調用click()。如果我進入下一頁,我將能夠找到類「breadcrumb_home_link」的東西。由於click()不起作用,因此找不到「breadcrumb_home_link」。 –

0

嗯,這是一個答案。我認爲這可能值得作爲硒人的錯誤提交。

我分解了WebObjects爲我創建的HTML。我正在使用WOActiveImage。如果我在WOImage周圍使用WOHyperlink,我幾乎得到了完全相同的URL,並且硒能夠跟隨鏈接。

的區別是這樣的:

<a name="19" class="access_my_schedule_link" 
    href="/cgi-bin/..."> 
<img width="74" border="0" height="64" src="/cgi-bin/..." ismap="ismap" /> 
</a> 

變成了:

<a name="19" class="access_my_schedule_link" 
    href="/cgi-bin/..."> 
<img width="74" border="0" height="64" src="/cgi-bin/..." /> 
</a> 

顯然使用ISMAP屬性上的標籤是有毒的硒。很奇怪。

嗯,我現在很好。

+0

請參閱http://code.google.com/p/selenium/issues/detail?id=5956 –

0

當你從.findElement方法中得到一個異常時,你所要做的就是優雅地處理這個異常,並且如果你在循環中完成所有的事情,你可以多次重試,而不會崩潰你的測試。如果你看看FluentWait類的.ignoring方法,那就是一個例子。

+0

從標籤內部的img標籤中除去ismap =「ismap」參數會導致硒正確跟蹤鏈接。爲什麼會這樣?如何捕捉異常並再次嘗試幫助? –

相關問題