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

I can't get the highlight_node-function to work.
Error message is
Odd name/value argument for subroutine 'WWW::Mechanize::Chrome::eval_in_page' at C:/Strawberry/perl/site/lib/WWW/Mechanize/Chrome.pm line 2001.
Here is an example code

use strict; use warnings; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; my $mech = WWW::Mechanize::Chrome->new; $mech->get('https://metacpan.org/'); sleep(1); my @nodes = $mech->xpath('//p'); $mech->highlight_node($mech,@nodes); sleep(3);

A workaround that seems to work for me is to use 'callFunctionOn'-function provided by WWW::Mechanize::Chrome and use same JavaScript as original code

highlight_nodes(@nodes); sub highlight_nodes { my @nodes = @_; foreach my $node (@nodes) { my $objectId = $$node{objectId}; $mech->callFunctionOn( 'function() { if( "none" == this.style.display ) { this.style.display= "block"; }; this.style.backgroundColor = "red"; this.style.border = "solid black 1px" }', objectId => $objectId, arguments => [] ); } }

Replies are listed 'Best First'.
Re: WWW::Mechanize::Chrome -> 'highlight_node'-Function
by Corion (Patriarch) on Apr 05, 2021 at 16:29 UTC

    Thank you very much for reporting this!

    That code is untested, as it requires human verification. I've added your code to the codebase and will soonish release it.