Thank you for investigating and identifying the problem.

We will proceed with your suggestion and track the HTMLUnit bug submission.

-----Original Message-----
From: Julien HENRY [mailto:henr...@yahoo.fr]
Sent: Wednesday, August 22, 2012 5:29 PM
To: Usage problems for JWebUnit
Subject: Re: [JWebUnit-users] clickElementByXPath failing

Clint,

I managed to found part of the problem. You are serving your webpages with 
xhtml namespace. See
xmlns="http://www.w3.org/1999/xhtml";


As a result your xpath expressions seems to nned to be namespace aware.
//* means any element in any namespace
but
//tr means tr in no namespace => not found


[1] was a good source of help even if it is a bit outdated. This strange xpath 
expression is working:
//:tr[@id='genTabViewId:genTabFrm:availableGroups:source::0']
so it seems the part of your UI updated by richfaces/ajax is in a different 
namespace.


Now question is why the namespace prefix is required after an AJAX partial 
refresh. I guess this is because richfaces send the ajax response with
content type = text/xml but not sure. I managed to create a reproducible test 
case with HtmlUnit API and I have submitted a bug [2].


Waiting for a potential fix in HtmlUnit I suggest you use //*[@id='xxx'] 
expression in order to not break your tests in the future if they provide a fix.


Hope this helps,

Julien


[1] http://old.nabble.com/Re%3A-htmlunit-and-xpath-p22810034.html
[2] 
https://sourceforge.net/tracker/?func=detail&aid=3560821&group_id=47038&atid=448266

>________________________________
> De : Julien HENRY <henr...@yahoo.fr>
>À : Usage problems for JWebUnit <jwebunit-users@lists.sourceforge.net>
>Envoyé le : Mercredi 22 août 2012 9h13
>Objet : Re: [JWebUnit-users] clickElementByXPath failing
>
>Hi guys,
>
>Jevon, in the same file I see:
>
><tr class="rich-picklist-source-row" 
>id="genTabViewId:genTabFrm:availableGroups:source::0">
>    <td class="rich-picklist-source-cell">
>        <img alt=" " 
> src="/saas/spring/a4j/g/3_3_3.Finalorg/richfaces/renderkit/html/images/spacer.gif"
>  style="width:1px;height:1px;"/>
>        CPARHAMsaasBill1Pri1
>        <input autocomplete="off" 
> id="genTabViewId:genTabFrm:availableGroups:source::0StateInput" 
> name="genTabViewId:genTabFrm:availableGroups:source::0" type="hidden" 
> value="124685"/>
>    </td>
></tr>
>
>
>so for me there is actually a tr with 
>id=genTabViewId:genTabFrm:availableGroups:source::0
>
>
>Clint, I have created a small test case (removing all relative js/css imports 
>from the html) and it is working fine:
>
>        URL url = this.getClass().getResource("/dump0b.html");
>        String urlStr = url.toString();
>        String baseUrl = urlStr.substring(0, urlStr.lastIndexOf("/"));
>        getTestContext().setBaseUrl(baseUrl);
>        setScriptingEnabled(false); //Need to disable JS because of missing 
> external references
>        beginAt("/dump0b.html");
>        
> assertNotNull(getElementById("genTabViewId:genTabFrm:availableGroups:source::0"));
>        assertEquals(1, 
> getElementsByXPath("//tr[@id='genTabViewId:genTabFrm:availableGroups:source::0']").size());
>
>
>So the problem should come from JS, but unfortunately I can't help without a 
>reproducible test case. I mean some standalone html + java like the previous 
>test. If you manage to extract all JS references of your framework (I guess 
>JSF + richfaces) and create a test case it would be possible to investigate.
>Regards,
>
>Julien
>
>
>>________________________________
>> De : jevon <je...@jevon.org>
>>À : Usage problems for JWebUnit <jwebunit-users@lists.sourceforge.net>
>>Envoyé le : Mercredi 22 août 2012 4h44
>>Objet : Re: [JWebUnit-users] clickElementByXPath failing
>>
>>Hi Clint,
>>
>>When I look at that source, it doesn't look like *any* object has an
>>id of 'genTabViewId:genTabFrm:availableGroups:source::0'. There is an
>>object with a @name of
>>'genTabViewId:genTabFrm:availableGroups:source::0', but that is an
>><input>...
>>
>>Perhaps the id="" attribute is not escaped properly (and the engine
>>has to drop it). The valid characters for an ID attribute in HTML 4.01
>>are /[a-z][a-z0-9:-_\.]*/i, so it's not that the id attribute is
>>incorrect - likewise, <tr>s are allowed in HTML 4.01 to have id
>>attributes.
>>
>>In fact, *none* of the elements in that XML source have an id
>>attribute. Interesting.
>>
>>Jevon
>>
>>On Sat, Aug 18, 2012 at 1:19 AM, Parham, Clinton <cpar...@biosignia.com> 
>>wrote:
>>> Hi Julien,
>>>
>>> Thank you for replying.
>>>
>>> I have attached the asXML dump of the page after Thread.sleep(10000) to 
>>> account for AJAX activity.
>>>
>>> When I open the dumped content in Chrome and enter the following into the 
>>> JavaScript console, the "tr" I'm trying to click is found:
>>> $x("//tr[@id='genTabViewId:genTabFrm:availableGroups:source::0']")
>>>
>>> Looking forward to your perspective.
>>>
>>> Clint
>>>
>>> -----Original Message-----
>>> From: Julien HENRY [mailto:henr...@yahoo.fr]
>>> Sent: Friday, August 17, 2012 3:25 AM
>>> To: Usage problems for JWebUnit
>>> Subject: Re: [JWebUnit-users] clickElementByXPath failing
>>>
>>> Hi,
>>>
>>> I've just tested to locate a tr element by id using the same xpath 
>>> expression and it is working fine. Are you not encountering timing issue? 
>>> If you are using AJAX to update the page there could be different results 
>>> depending on execution speed.
>>>
>>> Concerning diference between getPageSource and asXml Jevon is right: 
>>> getPageSource returns the original source returned by the server while 
>>> asXml is a dump of the current state of the DOM.
>>>
>>> Could you please send us the result of asXml() when your test failed?
>>>
>>> Regards,
>>>
>>> Julien
>>>
>>>
>>> ----- Mail original -----
>>>> De : "Parham, Clinton" <cpar...@biosignia.com>
>>>> À : Usage problems for JWebUnit <jwebunit-users@lists.sourceforge.net>
>>>> Cc :
>>>> Envoyé le : Vendredi 17 août 2012 4h57
>>>> Objet : Re: [JWebUnit-users] clickElementByXPath failing
>>>>
>>>> When executing getElementsByXPath("//tr") I get back 88 matches.
>>>>
>>>> But it gets more interesting:
>>>>
>>>> The following (from my original clickElementByXPath) returns zero matches:
>>>> getElementsByXPath("//tr[@id='genTabViewId:genTabFrm:availableGroups:source::0']");
>>>>
>>>> But this returns what I'm looking for (only changed "tr" to
>>>> "*"):
>>>> getElementsByXPath("//*[@id='genTabViewId:genTabFrm:availableGroups:source::0']");
>>>>
>>>> This is what the debugger returns when Inspecting the return value of the 
>>>> above
>>>> statement - you can see it is a "tr":
>>>> [IElement[name=tr wrapped=HtmlTableRow[<tr
>>>> class="rich-picklist-source-row"
>>>> id="genTabViewId:genTabFrm:availableGroups:source::0">]]]
>>>>
>>>> I would expect consistent results when calling both of these 
>>>> getElementsByXPath
>>>> methods. What's going on?
>>>>
>>>> Thanks.
>>>>
>>>> -----Original Message-----
>>>> From: jevon [mailto:je...@jevon.org]
>>>> Sent: Thursday, August 16, 2012 8:56 PM
>>>> To: Usage problems for JWebUnit
>>>> Subject: Re: [JWebUnit-users] clickElementByXPath failing
>>>>
>>>> Hi,
>>>>
>>>> I can't look at the JWebUnit source right now, but it sounds like
>>>> getPageSource() just dumps out the original source of the page, i.e.
>>>> without Javascript DOM modifications, whereas page.asXml() dumps the
>>>> runtime content of the page itself, i.e. after Javascript/AJAX has
>>>> modified the page. Or perhaps the source page does not validate, thus
>>>> some of the elements are lost.
>>>>
>>>> What happens if you execute getElementsByXPath("//tr")?
>>>>
>>>> Cheers
>>>> Jevon
>>>>
>>>> On Fri, Aug 17, 2012 at 8:47 AM, Parham, Clinton <cpar...@biosignia.com>
>>>> wrote:
>>>>>  Hello,
>>>>>
>>>>>  We're using JWebUnit 3 to test a JSF web application that uses JBoss
>>>> RichFaces AJAX enabled components.
>>>>>
>>>>>  At one point in the test, a call to
>>>> clickElementByXPath("//tr[@id='genTabViewId:genTabFrm:availableGroups:source::0']")
>>>> is made but it fails with this:
>>>>>
>>>>>  java.lang.AssertionError: Unable to locate element with xpath
>>>> "//tr[@id='genTabViewId:genTabFrm:availableGroups:source::0']"
>>>>>          at org.junit.Assert.fail(Assert.java:91)
>>>>>          at org.junit.Assert.assertTrue(Assert.java:43)
>>>>>          at
>>>> net.sourceforge.jwebunit.junit.WebTester.assertElementPresentByXPath(WebTester.java:2109)
>>>>>          at
>>>> net.sourceforge.jwebunit.junit.WebTester.clickElementByXPath(WebTester.java:2673)
>>>>>          at
>>>> com.xyz.util.EnrollmentUtil.setGeneralTabFields(EnrollmentUtiljava:165)
>>>>>          ...
>>>>>
>>>>>  Just before making the clickElementByXPath call, we execute
>>>> Thread.sleep(5000) to account for AJAX activity and then we dump the page
>>>> content two ways to see what's going on:
>>>>>  [1] FileUtils.writeStringToFile(new File(filename), getPageSource());
>>>>>  and
>>>>>  [2] HtmlUnitTestingEngineImpl engine = (HtmlUnitTestingEngineImpl)
>>>> getTestingEngine();
>>>>>  HtmlPage page = ((HtmlPage) engine.getCurrentWindow().getEnclosedPage());
>>>>>  FileUtils.writeStringToFile(new File(filename), page.asXml());
>>>>>
>>>>>  The dumps are different which is quite surprising. When viewing the file
>>>> generated by method [1] in Chrome, the "tr" element is not present.
>>>> But it is present when viewing the file generated by method [2].
>>>>>
>>>>>  What is happening?
>>>>>
>>>>>
>>>>>  The contents contained herein may contain confidential information. If 
>>>>> you
>>>> are not the intended recipient, you are hereby notified that any 
>>>> disclosure,
>>>> copying, distribution, printing or action taken on the contents is strictly
>>>> prohibited. If you have received this email in error, please notify the 
>>>> sender
>>>> immediately and delete this message.
>>>>>
>>>>>
>>>> ------------------------------------------------------------------------------
>>>>>  Live Security Virtual Conference
>>>>>  Exclusive live event will cover all the ways today's security and
>>>>>  threat landscape has changed and how IT managers can respond. Discussions
>>>>>  will include endpoint security, mobile security and the latest in malware
>>>>>  threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>>>>  _______________________________________________
>>>>>  JWebUnit-users mailing list
>>>>>  JWebUnit-users@lists.sourceforge.net
>>>>>  https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Live Security Virtual Conference
>>>> Exclusive live event will cover all the ways today's security and
>>>> threat landscape has changed and how IT managers can respond. Discussions
>>>> will include endpoint security, mobile security and the latest in malware
>>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>>> _______________________________________________
>>>> JWebUnit-users mailing list
>>>> JWebUnit-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Live Security Virtual Conference
>>>> Exclusive live event will cover all the ways today's security and
>>>> threat landscape has changed and how IT managers can respond. Discussions
>>>> will include endpoint security, mobile security and the latest in malware
>>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>>> _______________________________________________
>>>> JWebUnit-users mailing list
>>>> JWebUnit-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Live Security Virtual Conference
>>> Exclusive live event will cover all the ways today's security and
>>> threat landscape has changed and how IT managers can respond. Discussions
>>> will include endpoint security, mobile security and the latest in malware
>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>> _______________________________________________
>>> JWebUnit-users mailing list
>>> JWebUnit-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>>
>>> ------------------------------------------------------------------------------
>>> Live Security Virtual Conference
>>> Exclusive live event will cover all the ways today's security and
>>> threat landscape has changed and how IT managers can respond. Discussions
>>> will include endpoint security, mobile security and the latest in malware
>>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>> _______________________________________________
>>> JWebUnit-users mailing list
>>> JWebUnit-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>>
>>
>>------------------------------------------------------------------------------
>>Live Security Virtual Conference
>>Exclusive live event will cover all the ways today's security and
>>threat landscape has changed and how IT managers can respond. Discussions
>>will include endpoint security, mobile security and the latest in malware
>>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>_______________________________________________
>>JWebUnit-users mailing list
>>JWebUnit-users@lists.sourceforge.net
>>https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>>
>>
>>
>
>------------------------------------------------------------------------------
>Live Security Virtual Conference
>Exclusive live event will cover all the ways today's security and
>threat landscape has changed and how IT managers can respond. Discussions
>will include endpoint security, mobile security and the latest in malware
>threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>_______________________________________________
>JWebUnit-users mailing list
>JWebUnit-users@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/jwebunit-users
>
>
>


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JWebUnit-users mailing list
JWebUnit-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jwebunit-users

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
JWebUnit-users mailing list
JWebUnit-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jwebunit-users

Reply via email to