Trying to get xpath to recognize long string with possible special characters... not working

118 views
Skip to first unread message

bert

unread,
Sep 29, 2009, 9:55:34 PM9/29/09
to Watir General
Thanks in advance!

I am trying to click on the following element using xpath by
referencing its unique onclick property:

<a onclick="dijit.byId('queryDetail').href='DISPLAY-QUERY-SUMMARY.do?
taskId=6&amp;type=details'; dijit.byId('queryDetail').show(); return
false;" href="">details</a>

I have tried several of the following and not sure what Im doing
wrong. I keep getting a "NoMethodError: undefined method `click' for
nil:NilClass". As you can see the onclick property has various
apostrophes, ampersand, etc. Not sure if this is the cause of my
troubles.

I have tried:

@browser.element_by_xpath("//a[@onclick='dijit.byId(\'queryDetail
\').href=\'DISPLAY-QUERY-SUMMARY.do?taskId=6\&amp;type=details\';
dijit.byId(\'queryDetail\').show(); return false;']").click

@browser.element_by_xpath("//a[@onclick='dijit.byId
(&apos;queryDetail&apos;).href=&apos;DISPLAY-QUERY-SUMMARY.do?
taskId=0&amp;type=sql&apos;; dijit.byId(&apos;queryDetail&apos;).show
(); return false;']").click()

Bill Agee

unread,
Sep 30, 2009, 3:59:09 AM9/30/09
to watir-...@googlegroups.com
Would it work to use just a fragment of the onclick value?  If so, you can try locating the element using XPath string functions like this:

ie.link(:xpath, "//a[starts-with(@onclick, 'dijit')]").click

ie.link(:xpath, "//a[contains(@onclick, 'taskId=6')]").click

I may be missing a less complicated way to do this, though. :)

Thanks
Bill


On Tue, Sep 29, 2009 at 6:55 PM, bert <tumba...@yahoo.com> wrote:

Thanks in advance!

I am trying to click on the following element using xpath by
referencing its unique onclick property:

<a onclick="dijit.byId('queryDetail').href='DISPLAY-QUERY-SUMMARY.do?
taskId=6&type=details'; dijit.byId('queryDetail').show(); return

false;" href="">details</a>

I have tried several of the following and not sure what Im doing
wrong.  I keep getting a "NoMethodError: undefined method `click' for
nil:NilClass".  As you can see the onclick property has various
apostrophes, ampersand, etc.  Not sure if this is the cause of my
troubles.

I have tried:

@browser.element_by_xpath("//a[@onclick='dijit.byId(\'queryDetail
\').href=\'DISPLAY-QUERY-SUMMARY.do?taskId=6\&type=details\';

dijit.byId(\'queryDetail\').show(); return false;']").click

@browser.element_by_xpath("//a[@onclick='dijit.byId
('queryDetail').href='DISPLAY-QUERY-SUMMARY.do?
taskId=0&type=sql'; dijit.byId('queryDetail').show
(); return false;']").click() pos;).show
(); return false;']").click()


Željko Filipin

unread,
Sep 30, 2009, 4:27:38 AM9/30/09
to watir-...@googlegroups.com
On Wed, Sep 30, 2009 at 3:55 AM, bert <tumba...@yahoo.com> wrote:
> I have tried several of the following and not sure what Im doing
> wrong.

XPath is black magic for me, but there are a few tools that could help:

XPather - https://addons.mozilla.org/en-US/firefox/addon/1192
XPath Checker - https://addons.mozilla.org/en-US/firefox/addon/1095

Željko
--
http://watirpodcast.com/

bert

unread,
Sep 30, 2009, 9:48:39 AM9/30/09
to Watir General
Thanks Bill, that worked perfectly!

On Sep 30, 2:59 am, Bill Agee <billa...@gmail.com> wrote:
> Would it work to use just a fragment of the onclick value?  If so, you can
> try locating the element using XPath string functions like this:
>
> ie.link(:xpath, "//a[starts-with(@onclick, 'dijit')]").click
>
> ie.link(:xpath, "//a[contains(@onclick, 'taskId=6')]").click
>
> I may be missing a less complicated way to do this, though. :)
>
> Thanks
> Bill
>
Reply all
Reply to author
Forward
0 new messages