Hi,

it is possible to define and register custom XPath functions (look in
WebTest sources at the CleanTextFunction for instance) but I would be
carefully here as it is an area that has changed due to migration to
HtmlUnit-2.1 and that may change again.

In your case, what about just
<groovy>
def links =
step.context.currentResponse.getByXPath("//[EMAIL PROTECTED]'mybreadcrumb']/div
> /div/div[1]/a")

def link = links.size() > 1 ? links[-2] : links[-1]
link.click()
</groovy>

Cheers,
Marc.
-- 
Blog: http://mguillem.wordpress.com


Harihara Vinayakaram wrote:
> Hi
>    Here is what I am trying to do . My tests are in groovy not in xml .
> 
>    I am trying to choose a link to click based on the xpath .(i.e )
> choose the last but one link .
> 
>    The xpath expression I used is //[EMAIL PROTECTED]'mybreadcrumb']/div
> /div/div[1]/a[max(1,last()-1)]
> 
>    But from the stacktrace I  find that webtest is unable to find the
> function max
> 
>    What should I do to get Webtest find the function max
> 
> Regards
> Hari
> 
> 
> On Wed, May 21, 2008 at 1:50 PM, Marc Guillemot <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
>     Not sure to follow. EXSLT surely needs to be registered in some way.
> 
>     Alternatively you can write your own extension or, surely easier, use a
>     groovy step or write a custom step.
> 
>     Cheers,
>     Marc.
>     --
>     Blog: http://mguillem.wordpress.com
> 
> 
>     Harihara Vinayakaram wrote:
>     > I looked at the xalan implementation and figured out that the max
>     > function is not bundled and need a EXSLT support . The name space
>     > mentioned in dyn:max
>     >
>     > I looked around for a EXSLT.jar which I can put in the
>     webtest.home /lib
>     > . But there does not seem to be any .jar file . There seems to be
>     > support for xsl , but no jars .
>     >
>     > Let me know how to proceed
>     >
>     > Regards
>     > Hari
>     >
>     > On Sun, May 18, 2008 at 3:49 PM, Harihara Vinayakaram
>     <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     > <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
>     >
>     >     The error is
>     >     //[EMAIL PROTECTED]'mybreadcrumb']/div/div/div[1]/a[max(1,last()-1)]
>     >
>     >     and the stack trace says:
>     >
>     >     javax.xml.xpath.XPathExpressionException: Could not find
>     function: max
>     >
>     >
>     >
>     >       at
>     
> com.canoo.webtest.engine.xpath.XPathHelper.handleException(XPathHelper.java:265)
>     >       at
>     
> com.canoo.webtest.engine.xpath.XPathHelper.getByXPath(XPathHelper.java:307)
>     >       at
>     
> com.canoo.webtest.engine.xpath.XPathHelper.selectFirst(XPathHelper.java:278)
>     >
>     >
>     >
>     >       at
>     
> com.canoo.webtest.boundary.HtmlUnitBoundary.trySelectSingleNodeByXPath(HtmlUnitBoundary.java:63)
>     >       at
>     
> com.canoo.webtest.steps.request.AbstractIdOrLabelTarget.findClickableElementByXPath(AbstractIdOrLabelTarget.java:118)
>     >
>     >
>     >
>     >       at
>     
> com.canoo.webtest.steps.request.AbstractIdOrLabelTarget.findClickableElement(AbstractIdOrLabelTarget.java:82)
>     >
>     >
>     >
>     >     Regards
>     >     Hari
>     >
>     >     On Sun, May 18, 2008 at 3:44 PM, Harihara Vinayakaram
>     >     <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
>     >
>     >         Hi
>     >           That was a typo in what I typed . The error in the
>     stacktrace
>     >         says max: function not found
>     >
>     >         Regards
>     >         Hari
>     >
>     >
>     >         On Sun, May 18, 2008 at 3:23 PM, Dierk König
>     >         <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
>     >
>     >             wrong parens nesting
>     >
>     >             | I tried //abc[max((1,last()-1))]
>     >                                ^
>     >             max takes two args but you give it only one
>     >
>     >             cheers
>     >             Dierk
>     >
>     >             |
>     >             | But I am getting a max class not found exception
>     when I run
>     >             | with webtest. . I guess this means that xalan's
>     exslt is not
>     >             | bundled in the library. I tried copying saxon.jar
>     which has a
>     >             | minimax function into .groovy/lib but that does not work
>     >             |
>     >             | Any ideas
>     >             |
>     >             |
>     >             | On Fri, May 16, 2008 at 10:07 PM, Dierk König
>     >             | <[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]> <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>>
>     >             wrote:
>     >             |
>     >             |
>     >             |       how about
>     >             |       //abc[max(1,last()-1)]
>     >             |       ?
>     >             |
>     >             |       BTW: abc[x] is short for abc[position()=x],
>     which means
>     >             | it is _not_ the
>     >             |       xth abc in the document but an abc that is the xth
>     >             | child of whatever
>     >             |       parent.
>     >             |
>     >             |       cheers
>     >             |       Dierk
>     >             |
>     >             |
>     >             |       | -----Original Message-----
>     >             |       | From: [EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     >             <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>
>     >             |
>     >             |       | [mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     >             <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>] On Behalf Of
>     >             | George Policello
>     >             |       | Sent: Freitag, 16. Mai 2008 17:54
>     >             |       | To: [email protected]
>     <mailto:[email protected]>
>     >             <mailto:[email protected]
>     <mailto:[email protected]>>; Harihara Vinayakaram
>     >             |       | Subject: RE: [Webtest] Re: XPath
>     implementation in
>     >             WebTest
>     >             |       |
>     >             |       | I do not have an XPath manual in front of me at
>     >             the moment
>     >             |       | but wonder if this would work.
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       | //abc[last()-1] | //abc[last()]
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       | It would in some scripting languages and some
>     >             | compiled languages.
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       | Also, a conditional could probably work
>     using the
>     >             "nilled(
>     >             |       //abc[last() -1] )" function in XPath.
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       | George
>     >             |       |
>     >             |       | ________________________________
>     >             |       |
>     >             |       | From: [EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     >             <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>
>     >             |       | [mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     >             <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>>] On Behalf Of Harihara
>     >             |       | Vinayakaram
>     >             |       | Sent: Friday, May 16, 2008 8:40 AM
>     >             |       | To: [email protected]
>     <mailto:[email protected]>
>     >             <mailto:[email protected]
>     <mailto:[email protected]>>
>     >             |       | Subject: [Webtest] Re: XPath implementation
>     in WebTest
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       | I am sorry but the xpath expression works
>     the same
>     >             way in
>     >             |       | Saxon as it does in webtest .
>     >             |       | So maybe I am looking for an xpath
>     expression that
>     >             gets the
>     >             |       | only node even if the expression is last() -1
>     >             |       |
>     >             |       | Regards
>     >             |       | Hari
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       | On Fri, May 16, 2008 at 8:49 PM, Harihara
>     Vinayakaram
>     >             |       | <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>     <mailto:[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>> wrote:
>     >             |       |
>     >             |       | Hi
>     >             |       |   I am not sure if this is the right place
>     to ask this
>     >             |       | question . But anyway
>     >             |       |
>     >             |       | My understanding is that the xpath exression
>     >             //abc[last()-1]
>     >             |       | will return the last but one element named abc .
>     >             |       |
>     >             |       | It works most of the times except when there
>     is only
>     >             | one element .
>     >             |       |
>     >             |       | In that case WebTest returns element not found
>     >             while others
>     >             |       | like saxon for example returns the last
>     element .
>     >             |       |
>     >             |       | Is this a bug ? or is my understanding wrong
>     >             |       |
>     >             |       | Regards
>     >             |       | Hari
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |       |
>     >             |
>     >             |       _______________________________________________
>     >             |       WebTest mailing list
>     >             |       [email protected]
>     <mailto:[email protected]> <mailto:[email protected]
>     <mailto:[email protected]>>
>     >             |       http://lists.canoo.com/mailman/listinfo/webtest
>     >             |
>     >             |
>     >             |
>     >             |
>     >
>     >
>     >
>     >
> 
>     _______________________________________________
>     WebTest mailing list
>     [email protected] <mailto:[email protected]>
>     http://lists.canoo.com/mailman/listinfo/webtest
> 
> 


_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest

Reply via email to