There is a link on a page, and I want to go to it but it just a javascript command. How with mechanize do I go to the link?
<a href="javascript:__doPostBack(ctl54$cphMainContent$resultsGrid$ctl54$ctl25$ctl62$ctl13,88)"><span>abc</span></a>
Without the page and its HTML and JS one can only guess. Note that the
follow_link()methods don't work with JS links. The method below does, but of course I cannot test without the page.Probably the best bet is to get link(s) as DOM object(s) for the
clickmethodThere are also
textandtext_containsrelevant options (instead oftext_regex), along with a number of others. Note thatclickmethod will wait, on a list of events, before returning. See for example this recent post. This is critical for pages that take longer to complete.See docs for
find_link_dom()andclickmethods. They aren't very detailed or rich in examples but do provide enough to play with and figure it out.If you need to interrogate links use
find_all_links_dom(), which returns an array or a reference to array (depending on context) of Firefox's DOM asMozRepl::RemoteObjectinstances.See the page for MozRepl::RemoteObject to see what you can do with it. If you only need to find out which link to click the options for
find_link_dom()should be sifficient.This has been tested only with a toy page, that uses
__doPostBacklink, with<span>in the link.