Skip Menu |

This queue is for tickets about the WWW-Mechanize-FireFox CPAN distribution.

Report information
The Basics
Id: 62086
Status: resolved
Priority: 0/
Queue: WWW-Mechanize-FireFox

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.33
Fixed in: (no value)



Subject: follow_link() hangs on links that don't lead to a new page
The following illustrates the problem: use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new; $mech->get("http://www.google.com"); print "Following...\n"; $mech->follow_link( url_regex => qr/preferences/ ); print "Done.\n"; __END__ It clicks on the "Settings" link on the Google home page which causes a Javascript drop down menu to appear. follow_link() then hangs, presumably waiting for a page load. I have this problem on other web sites. It seems follow_link() will hang on any link that causes a DOM change but not page reload. Is there a work around?
Subject: Re: [rt.cpan.org #62086] follow_link() hangs on links that don't lead to a new page
Date: Tue, 12 Oct 2010 22:56:13 +0200
To: bug-WWW-Mechanize-FireFox [...] rt.cpan.org
From: Max Maischein <corion [...] corion.net>
Hello, Show quoted text
> The following illustrates the problem: > > use WWW::Mechanize::Firefox; > > my $mech = WWW::Mechanize::Firefox->new; > > $mech->get("http://www.google.com"); > print "Following...\n"; > $mech->follow_link( url_regex => qr/preferences/ ); > print "Done.\n"; > __END__ > > It clicks on the "Settings" link on the Google home page which causes a > Javascript drop down menu to appear. follow_link() then hangs, > presumably waiting for a page load. > > I have this problem on other web sites. It seems follow_link() will > hang on any link that causes a DOM change but not page reload. > > Is there a work around?
Yes. Pass synchronize => 0 when making the ->click() call. ->follow_link() does not support that yet, but that should be implemented there as well, if the API allows for it. $mech->click({ xpath => '//a[ contains( text(), "Preferences") ]}, synchronize => 0 ); Unfortunately, XPath doesn't allow for regular expressions, so you'll have to do with substring matches... -max
Subject: Re: [rt.cpan.org #62086] follow_link() hangs on links that don't lead to a new page
Date: Tue, 12 Oct 2010 17:35:57 -0400
To: bug-WWW-Mechanize-FireFox [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
On 2010.10.12 4:56 PM, Max Maischein via RT wrote: Show quoted text
> Yes. Pass > > synchronize => 0 > > when making the ->click() call. ->follow_link() does not support that > yet, but that should be implemented there as well, if the API allows for it. > > $mech->click({ xpath => '//a[ contains( text(), "Preferences") ]}, > synchronize => 0 ); > > Unfortunately, XPath doesn't allow for regular expressions, so you'll > have to do with substring matches...
Thanks for the quick response! This worked: $mech->get("http://www.google.com"); $mech->click({ xpath => q{//div[@id='guser']//a[@class='gb3']}, synchronize => 0 }); I need to click on a very specific link which is difficult to specify with an xpath. In this case there are sets of very similar links and I only care about the visible ones. Its the "Web | Yellowbook | eBay" links at the top of http://charter.net/ my @buttons = grep { $mech->is_visible($_) } $mech->xpath(q{//div[@class="search_cat"]//a}); $mech->follow_link($buttons[1]); click() can't do this, as documented, but I dug into the code and discovered the undocumented "dom" option which worked. my @buttons = grep { $mech->is_visible($_) } $mech->xpath(q{//div[@class="search_cat"]//a}); $mech->click({ dom => $buttons[1], synchronize => 0 }); Its handy! Should it be documented? -- 101. I am not allowed to mount a bayonet on a crew-served weapon. -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army http://skippyslist.com/list/
Subject: Re: [rt.cpan.org #62086] follow_link() hangs on links that don't lead to a new page
Date: Tue, 12 Oct 2010 23:42:01 +0200
To: bug-WWW-Mechanize-FireFox [...] rt.cpan.org
From: Max Maischein <corion [...] corion.net>
Hello Michael, Show quoted text
>> Unfortunately, XPath doesn't allow for regular expressions, so you'll >> have to do with substring matches...
> > Thanks for the quick response! This worked: > > $mech->get("http://www.google.com"); > $mech->click({ > xpath => q{//div[@id='guser']//a[@class='gb3']}, > synchronize => 0 > });
Cool! Show quoted text
> click() can't do this, as documented, but I dug into the code and discovered > the undocumented "dom" option which worked. > > my @buttons = grep { $mech->is_visible($_) } > $mech->xpath(q{//div[@class="search_cat"]//a}); > $mech->click({ dom => $buttons[1], synchronize => 0 }); > > Its handy! Should it be documented?
Yes - I actually use it quite much, so maybe that's how it flew under my documentation radar. 0.34 will have it, thanks for the suggestion. I also accept patches at the github repository, if you feel that other things need improvement :) -max
RT-Send-CC: schwern [...] pobox.com
I've just released 0.34 which should address the issue by providing an extended API for ->follow_link() and also documenting the "dom" option to ->click()