Browser hangs when click() method called on a javascript link
sdondley opened this issue · comments
Let's say you have a link that when clicked triggers an ajax call to load more content into the page. If the click()
method is used to click the link, the browser hangs because it never receives an HTTP::Response
back. I've hacked together a fix for my own purposes but it would be better to make a proper fix. I'm looking for guidance on what that fix would be. Here's my temporary hack which modifies the _mightNavigate
call found at the end of the click
method:
my $response = $x ?
$self->_mightNavigate( sub {
$self->driver->send_message('Runtime.callFunctionOn', objectId => $id, functionDeclaration => 'function() { this.click(); }', arguments => []);
}, %options)
:
$self->_mightNavigate( sub {
$self->driver->send_message('Runtime.callFunctionOn', objectId => $id, functionDeclaration => 'function() { this.click(); }', arguments => []);
}, %options)
->get;
The way it works is if I pass in a value for $x
to the method, it will call _mightNavigate
without the get
method.
The (more) correct solution would be to use the intrapage
option to ->click
:
$mech->click( { selector => '.foo', intrapage => 1 });
Currently, I have a problem coming up with a test case where the detection for "no HTTP response will come" fails. If you have a slimmed down test case, this would help.
Unfortunately, I don't remember where I encountered this problem. It may have been the Twitter login button on their web page but I'm not sure.
I think I found it. It looks like it's a link in Facebook group discussions:
click( { xpath => $s->xpath . '//div[@class="UFIList"]/div/div/div[1]//a[@class="UFIPagerLink"]' }, 1 );
Thank you for digging into this. If you can create a page that reproduces the behaviour from that, that would be great. As it is, I can't replicate it and I don't even have an URL to reproduce the behaviour.
I was just looking it over. It looks like Facebook changed their ids quite a bit so it would be a nightmare to track down.
I'd try using the link this guy was talking about: https://www.perlmonks.org/?node_id=11105389
Yes, I could go rummaging around in an ill-defined nest of web pages. It seems that the problem cannot be reproduced at this time.
I'm closing this bug until a reproducible case is presented.
OK, if I run across it again, I'll let you know.