def self.click_link(link_spec,index = 0,wait_secs=0)
Scrubyt.log :ACTION, "Clicking link specified by: %p" % link_spec
if link_spec.is_a?(Hash)
elem = XPathUtils.generate_XPath(CompoundExampleLookup.find_node_from_compund_example(@@hpricot_doc, link_spec, false, index), nil, true)
result_page = @@agent.element_by_xpath(elem).click
else
@@agent.link(:innerHTML, Regexp.escape(link_spec)).click
end
sleep(wait_secs) if wait_secs > 0
@@agent.wait
@@current_doc_url = @@agent.url
@@mechanize_doc = "<html>#{@@agent.html}</html>"
@@hpricot_doc = Hpricot(PreFilterDocument.br_to_newline(@@mechanize_doc))
Scrubyt.log :ACTION, "Fetching #{@@current_doc_url}"
end