Selenium finds A tag but click() has no effect?

536 Views Asked by At

I have a dynamic web application built with WebObjects. There is a link that my test code is trying to find. I do a getPageSource() right before I find it and that is below.

I find the tag successfully. Then I click on it. Nothing happens. The tag I am looking for on the next page does not get found.

So, what about a tag can make it not respond to the click? There is no js attached to it. It is inside a span and surrounds an image, but that is all.

When the test code finishes executing, I can click on the link manually and I see the next page. So what up? Any ideas?

 [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 APPLiveDriver$4@337b4703
 [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)
3

There are 3 best solutions below

3
Karloss On

It seems Selenium webDriver couldn't find element, try to search by xpath. Also it would be nice if you provide html source (it can be copied from firebug). Upd.: thanks to response. You have class name "breadcrump_home_link" in the code, but different class name in the test: "access_my_schedule_link".

0
Ray Kiddy On

Well, it is an answer. I think this might be worth filing as a bug with the selenium people.

I took apart the HTML that WebObjects was creating for me. I was using a WOActiveImage. If I use a WOHyperlink around a WOImage, I got almost the exact same URL, and selenium was able to follow the link.

The difference was this:

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

became:

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

Apparently using the ismap attribute on the A tag is toxic to Selenium. Very odd.

Well, I am good for now.

1
djangofan On

When you get an exception from the .findElement method, all you have to do is handle the exception gracefully and if you do it all in a loop, you can retry as many times as you want without crashing your test. If you look at the .ignoring method of the FluentWait class, that is an example.