1

Using ruby, how can I get webdriver to click on a javascript link?

The link I'm trying to click on is: <a class="TabOff" href=" javascript:showConfirm('/campustoolshighered/k12_admin_admin_menu.do');">Administration </a>

Would I be able to trigger the javascript with a keyPress event? If so, does anyone know the syntax for doing that? I've had trouble finding a good reference for webdriver -- though I understand that it'll probably get better as it moves out of beta.

I've also looked at firewatir and mechanize. If you have reason to think that one of these would be a better approach then please let me know and why. It needs to be able to click on javascript links and submit form data from a spreadsheet or csv file.

Thanks for the help!

require 'rubygems'
require 'watir-webdriver'

ff=Watir::Browser.new(:firefox)
ff.goto("http://my-web-address")

#Put your user name. 
ff.text_field(:name,"user").set("my-username")

#Put your password.
ff.text_field(:name,"pass").set("my-passwd")

#Click Sign In button.
ff.button(:value,"Login").click

#Click on Administration tab. <-- This does not work!!
ff.link(:text, "Administration").click

1 Answer 1

1

Click will indeed trigger the javascript. Are you sure It is actually finding the link?

Your HTML source code shows a space characters after the word 'Administration ' Maybe that the cause.

Check if

ff.link(:text, "Administration").exists?

returns true.

Or try a different match:

ff.link(:class => 'tabOff').click

Note: You can also use regexp for the :text as well, such as

ff.link(:text, /Administration/)

Hope to help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.