Unable to click the link (anchor and span)and use xpath in ruby script

1,083 views
Skip to first unread message

Hari

unread,
Sep 7, 2011, 1:49:50 AM9/7/11
to Watir General
I'm trying toclick a link the <a>anchor tags from
the html shown below.
I'm running firewatir on Windows Xp and have the
jssh plugin installed.


<li onkeydown="return webFXTreeHandler.keydown(this, event)"
class="navTreeLeaf" id="cwc_menu_local:ROOT.Find a Request"
onclick="webFXTreeHandler.toggleDIV(this);">
<a onblur="webFXTreeHandler.blur(this);"
onfocus="webFXTreeHandler.focus(this);"
id="cwc_menu_local:ROOT.Find a Request-anchor"
onclick="var stat=webFXTreeHandler.select(this);
if(!stat)return stat;;"
ondblclick="webFXTreeHandler.selectOpen(this);
" target="detail" href="/smweb/cwc/nav.menu?name=navStart&amp;id=ROOT
%2FFind%20a%20Request">
<span class="cwc_navMenuLabel">Find a Request</span></a></li>

my code is as below and click the link

ff.link(:text, 'Find a Request').click

ff.link(:xpath, 'html/body/div[2]/ul/li').click

ff.link(:xpath, 'html/body/div[2]/ul/li[4]/a[1]/span').click

ff.link(:xpath, "//a[@id="cwc_menu_local:ROOT.Find a
Request"]/").click

however the output of the text fails with the error:

Unable to locate element, using :xpath, "//a[@id=\\\"cwc_menu
_local:ROOT.Find a Request\\\"]/
input" (Watir::Exception::UnknownObjectException
)
from C:/Ruby187/lib/ruby/gems/1.8/gems/firewatir-1.9.3/lib/
firewatir/
element.rb:1081:in `click'

tell me were i have to make correction so that i can click a link

id="cwc_menu_local:ROOT.Find a Request-anchor"
onclick="var stat=webFXTreeHandler.select(this);

tell me to write a ruby script by using this HTML tag

Xpath i got using fire bug is
ff.link(:xpath, 'html/body/div[2]/ul/li[4]/a[1]/span').click

Anyone know where i've gone wrong , please correct me to rectify the
error soon

Thanks in advance

Rahul Sharma

unread,
Sep 7, 2011, 5:01:24 AM9/7/11
to watir-...@googlegroups.com
The text you are looking for to click is in the span tag and not the <a> tag.

so this should work.

ff.span(:text => 'Find a request').click




--
Regards,

Rahul Sharma
Ph:+44 7800 736851

Raveendran P

unread,
Sep 7, 2011, 5:02:10 AM9/7/11
to watir-...@googlegroups.com
Hi Hari,

Have your tried

ff.link(:id, 'cwc_menu_local:ROOT.Find a Request-anchor').exist?

and

ff.link(:id, 'cwc_menu_local:ROOT.Find a Request-anchor').click

and

ff.link(:id, 'cwc_menu_local:ROOT.Find a Request-anchor').fire_event("onlclick")


Thanks
Ravi P






--
Regards,
P.Raveendran
http://raveendran.wordpress.com

Hari

unread,
Sep 13, 2011, 6:27:13 AM9/13/11
to Watir General
I am trying to click on a text inside a span in my web page. But
it is not clicking it. when i try to flash it. it flashes.

I also tried to user fire_event("onclick"), still it is not clicking
it.

ff.span(:id, 'cwc_masthead_username').click

puts ff.show_spans()

ff.spans.each{|s|puts s.to_s}

ff.spans[1].to_s

ff.span(:class, 'cwc_navMenuLabel').click

ff.link(:text, 'Find a Request').click

ff.link(:xpath, 'html/body/div[2]/ul/li[4]/a/span').click

ff.link(:xpath, "//*[@id='cwc_menu_local:ROOT.Find a Request-anchor']/
span").click

ff.element_by_xpath("//html/body/div[2]/ul/li[4]/a/span[text='Find a
Request']").click

ff.link(:id , 'cwc_menu_local:ROOT.Find a Request-anchor').click

ff.link(:text => 'Find a Request',:index =>4).click

This is the HTML tag

<a id="cwc_menu_local:ROOT.Find a Request-anchor"

onblur="webFXTreeHandler.blur(this);"
onfocus="webFXTreeHandler.focus(this);"

onclick="var stat=webFXTreeHandler.select(this);
if(!stat)return stat;;"
ondblclick="webFXTreeHandler.selectOpen(this);"
target="detail" href="/smweb/cwc/nav.menu?name=navStart&amp;id=ROOT
%2FFind%20a%20Request"
class="selected-inactive"><span class="cwc_navMenuLabel">Find a
Request</span></a>


I would think span element includes anchor want toclick to the
anchor instead of span

I want to click on the "Find a Request" text link here and it should
go to desired location.


Appreciate your help

Thank you,
Hari


Rahul Sharma

unread,
Sep 13, 2011, 7:23:53 AM9/13/11
to watir-...@googlegroups.com
 ff.link(:id , 'cwc_menu_local:ROOT.Find a Request-anchor').click This should have worked. Can you check if the link you are trying to click is inside a frame!!




--
Regards,
Reply all
Reply to author
Forward
0 new messages