element in html
#### # it assumes a ./content.html is present on same dir #!/usr/bin/env perl use strict; use warnings; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use FindBin; Log::Log4perl->easy_init($ERROR); my %mech_params = ( headless => 0, launch_arg => [ '--window-size=600x800', '--password-store=basic', # do not ask me for stupid chrome account password # '--remote-debugging-port=9223', # '--enable-logging', # see also log above '--disable-gpu', '--no-sandbox', '--ignore-certificate-errors', '--disable-background-networking', '--disable-client-side-phishing-detection', '--disable-component-update', '--disable-hang-monitor', '--disable-save-password-bubble', '--disable-default-apps', '--disable-infobars', '--disable-popup-blocking', ], ); my $mech = WWW::Mechanize::Chrome->new(%mech_params); $mech->get('file://'.$FindBin::Bin.'/content.html'); my $elem; $elem = eval { $mech->xpath('//div[@id="id1"]', single=>1) }; die "non-dynamic element not found" unless defined $elem; $mech->sleep(2); my $ret = eval { $mech->wait_until_visible( xpath=>'//div[@id="id2"]', timeout=>2, # it's already there after 1.5s ); 1; }; die "dynamic element not found" unless defined($ret) && ($ret==1) && ! $@; print "OK dynamic element found!\n"; #### document.evaluate('//div[@id="abc"]', null, document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength;