eshwar has asked for the wisdom of the Perl Monks concerning the following question:


Hi Monks,
(Sorry, its a bit lengthy!)
At the risk of sounding crazy, my situation is this: I have a web page with a table of names which are text links to other pages. Each of these links has to be opened and saved as a seperate HTML file. I wont be able to use "ahref" tag to identify links because the names lead to a Java Script which fetchs data from a database and populates it into a template webpage (so the link of each name will lead to the same URL) Manually saving 14,000 pages is a nightmare for me!

So I wanted to build a "text search and mouse click" action i.e. a script that would
1. Search for a list of names in a browser (which has been extracted with HTML::TableExtract)
2. On finding a match, trigger a mouse click on the name in the browser
3. Save the opened page
4. Go back to the previous page (homepage)
5. Search for the next name on the list and go on.

I am not sure how to trigger a mouse click in Perl if it is possible (Im quite sure I can manage the rest)
Please help me out in finding my way out of this problem.

Thanks,
Eshwar.
  • Comment on Is it possible to trigger a mouse click action in a browser using Perl?

Replies are listed 'Best First'.
Re: Is it possible to trigger a mouse click action in a browser using Perl?
by james2vegas (Chaplain) on Aug 14, 2009 at 04:42 UTC
    This is similar to a question posted just now. Are you using WWW::Mechanize or some module that uses an actual browser (like Win32::IE::Mechanize or Mozilla::Mechanize)?

    You can click on links, but if you are using Mech, you won't be able to run the javascript. If you know enough javascript you could probably re-write the function into Perl, otherwise use a Mech that has a browser backend.
      James2Vegas, Thanks for the reply. I am using Win32::IE::Mechanize. I was able to click on "buttons" (like "sign in" in gmail etc. ) on pages with the click and click_button functions but not "text links" (like the names of Other Users listed in the panel, right hand side of your page).
      Is there a work around to do this?
      Please enlighten me..

      Thanks,
      Eshwar.
        Using the base Win32::IE::Mechanize object you can get the agent which is the Internet Explorer Automation object and from there you can get the Document object, basically equivalent to the Document object in DOM/Javascript.

        Thanks to Anonymous Monk downthread, we learn that Microsoft's "relaxed" attitude towards standards allows the OP to indeed use the click() method on their links. Unfortunately the click() method only works on input elements, not links, so you would need to work out how the link calls the javascript. If the links' hrefs were set to javascript urls, doing something like $ie->get('javascript:codehere') (where that matches the href of the link) would also work, but if it is attached as an event handler you would need to execute the code in the event handler.

        Failing all this, you could work out what the javascript is doing in terms of submitting and retrieving data and use Mech to reproduce it.