[JWebUnit-users] Accessing dynamic images created in Javascript
Brought to you by:
henryju
From: Jeff D. <jef...@ya...> - 2010-09-30 00:57:44
|
Hi all, Another quick question. I have some javascript/JQuery that is creating an img dynamically. I tried using the assertElementPresentByXPath()method but that is not behaving as expected. For example, I have an Ajax call that builds the img tag as follows: xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { try { tableHTML = "<h2>Administrators <img id=\"inviteAdmin\" title=\"Invite an administrator\" class=\"clickable\" src=\"images/icon_envelope.png\" onclick=\"showInviteAdministrator();\" width=\"48\" height=\"48\" alt=\"Invite administrator\"></img></h2><table>"; result = JSON.parse(xmlhttp.responseText); My JWebUnit test file then tries the following assert: assertElementPresentByXPath("//img[@src='images/icon_envelope.png']"); Here is the resulting (truncated) trace when the assert fails: junit.framework.AssertionFailedError: Unable to locate element with xpath "//img[@src='images/icon_envelope.png']" at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.assertTrue(Assert.java:20) at net.sourceforge.jwebunit.junit.WebTester.assertElementPresentByXPath(WebTester.java:2034) at net.sourceforge.jwebunit.junit.WebTestCase.assertElementPresentByXPath(WebTestCase.java:1619) Now I am reasonably good with XPath, but I also know how finicky it can be and how easy it is to overlook something. Here are my questions: * Am I even going about this the right way? * Can JWebUnit handle dynamic elements created by javascript? * Is this something HtmlUnit is better suited? Thanks in advance for your help. - Jeff |