Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep statements needed in code to avoid errors #59

Open
sdondley opened this issue Jul 19, 2021 · 8 comments
Open

Sleep statements needed in code to avoid errors #59

sdondley opened this issue Jul 19, 2021 · 8 comments

Comments

@sdondley
Copy link
Contributor

I've got chromium installed on a Debian 10 box with 8 GB of ram. I will frequently, but not always, see errors unless I place sleep statements in the code like so:

#!/usr/bin/perl
use File::Temp 'tempdir';
use Time::HiRes 'usleep';
use Log::Log4perl qw(:easy);
use WWW::Mechanize::Chrome;

Log::Log4perl->easy_init($ERROR);
my $mech = WWW::Mechanize::Chrome->new(sync => 1, launch_exe => '/usr/bin/chromium', headless => 1, incognito => 1, data_directory => tempdir( CLEANUP => 1 ), profile => '/home/admin');
$mech->get('http://exmaple.com/wp-login.php');

usleep 500000;
$mech->submit_form( with_fields => { log => 'user', pwd => 'pass' } );

usleep 500000;
print $mech->content;

Here's an example of the errors I'll get without the sleep statements:

Bad luck: Node with nodeId 0 found. Info for this one cannot be retrieved at /usr/local/share/perl/5.28.1/WWW/Mechanize/Chrome.pm line 4026.
No node with given id found

-32000 at /usr/local/share/perl/5.28.1/Chrome/DevToolsProtocol/Target.pm line 502
Node 0 has gone away in the meantime, could not resolve at /usr/local/share/perl/5.28.1/WWW/Mechanize/Chrome/Node.pm line 206.
Can't call method "send_message" on an undefined value at /usr/local/share/perl/5.28.1/WWW/Mechanize/Chrome/Node.pm line 95.

When this error occurs, the HTML does not get printed to the screen at all as execpted.

A less frequent error I see is this one:

No search session with given id found

-32000 at /usr/local/share/perl/5.28.1/Chrome/DevToolsProtocol/Target.pm line 502

Other times, the script will run but will print this error before printing the content of the page:

No node with given id found

-32000 at /usr/local/share/perl/5.28.1/Chrome/DevToolsProtocol/Target.pm line 502
Node 157 has gone away in the meantime, could not resolve at /usr/local/share/perl/5.28.1/WWW/Mechanize/Chrome/Node.pm line 206.

Are there any settings I can use to avoid these errors? I'd prefer not to have to litter my code with sleep statements.

@Corion
Copy link
Owner

Corion commented Jul 19, 2021

Oh - I encounter these problems with nodes getting nodeId 0 , but I didn't know you can avoid them by sleeping a bit. I'll investigate whether sleeping within ->xpath prevents this problem.

If you have a reliable way of producing the problem, I would very much like that, as currently the problem occurs for me in maybe 1 of 20 test runs or so.

@sdondley
Copy link
Contributor Author

It happens for me nearly 100% of the time in the code sample above. If I remove the $mech->submit_form line in the sample code, the error occurs much less frequently.

If it'll help, I can send you a user name, password and url for the site (it's just a staging site). How can I get those credentials to you securely?

@nico-8
Copy link

nico-8 commented Jan 4, 2022

@Corion any news of this issue ?
I have the same problems as @sdondley

@Corion
Copy link
Owner

Corion commented Jan 8, 2022

Unfortunately, the experiment with sleeping did not help with the issue. I can replicate the issue, but have not found ways to fix the issue.

@nico-8
Copy link

nico-8 commented Jan 8, 2022

Is this specific to Perl ? I mean there is implementation of Chrome automation in other language. Maybe a track to follow ?
For me, I test with $mech->selector and $mech->xpath, I always have the issue.

@Corion
Copy link
Owner

Corion commented Jan 9, 2022

I think I found the same error elsewhere [1], and the solution seems to be to call DOM.getDocument only once per page. I'm in the process of going through the codebase and reworking it, but I'm not sure if it really works. But thanks for the idea of looking at how others cope with this problem!

1

@nico-8
Copy link

nico-8 commented Jan 9, 2022

Excellent news !
Hope it will work.
If you need more inspiration, follow this 1.
And of course, submit your Awesome work to this list 😎
I really want to use Perl to automate Chrome.

@nico-8
Copy link

nico-8 commented Jan 18, 2022

@Corion have a look at Selenium::Chrome, it is working well for me.
So maybe, it could be interesting to have a look how they implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants