Question

I'm trying to write a script that will automatically click a button when entering a site.

The HTML of the site is as follows:

<span id="zolaDisclaimerButton" class="dijitReset dijitStretch dijitButtonContents" waistate="labelledby-zolaDisclaimerButton_label" wairole="button" dojoattachpoint="titleNode,focusNode" role="button" aria-labelledby="zolaDisclaimerButton_label" tabindex="0" title="I acknowledge this disclaimer... Let ZoLa begin!" style="-moz-user-select: none;">

I have tried the following and they don't work:

browser.span(:id, "zolaDisclaimerButton").click
browser.button(:id, "zolaDisclaimerButton").click

How do I go about clicking those types of button? The URL in question is: http://gis.nyc.gov/doitt/nycitymap/template?applicationName=ZOLA

EDIT: this is the code I use:

require "watir"
browser = Watir::Browser.new
browser.goto "http://gis.nyc.gov/doitt/nycitymap/template?applicationName=ZOLA"
browser.span(:id, "zolaDisclaimerButton").click
puts "fin"

It navigates to the page, doesn't click anything, then prints 'fin' (to let me know it's done). No exception is thrown.

Was it helpful?

Solution

If the page is not loading in time, you can add waits - see http://watirwebdriver.com/waiting/. These wait methods will wait until either the condition is met or a time limit is exceeded. It is better than using sleep since it only waits as long as needed (rather than waiting 2 seconds for something that loads in 1 second).

In this case, use the when_present method on the span before clicking it:

require "watir"
browser = Watir::Browser.new
browser.goto "http://gis.nyc.gov/doitt/nycitymap/template?applicationName=ZOLA"
browser.span(:id, "zolaDisclaimerButton").when_present.click
puts "fin"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top