Issue
I am exploring Selenium::Remote::Driver - specifically running javascript.
However, in running this - which I think is pretty much the example in the documentation page:
use FindBin qw( $RealBin );
use Selenium::Chrome qw( );
$\ = "\n"; $, = "\t";
my $web_driver = Selenium::Chrome->new(
binary => "/usr/bin/chromedriver",
);
print $web_driver->has_javascript;
$web_driver->get($ARGV[0]);
my $script = q{
var arg1 = arguments[0];
var elem = window.document.findElementById(arg1);
return elem;
};
my $elem = $web_driver->execute_script($script,'hnmain');
print $elem;
I get this error:
Error while executing command: javascript error: javascript error: window.document.findElementById is not a function
(Session info: chrome=120.0.6099.216) at /home/simone/perl5/perlbrew/perls/perl-5.30.2/lib/site_perl/5.30.2/Selenium/Remote/Driver.pm line 411.
at /home/simone/perl5/perlbrew/perls/perl-5.30.2/lib/site_perl/5.30.2/Selenium/Remote/Driver.pm line 361.
Why is that? what am I doing wrong?
The line with print $web_driver->has_javascript;
prints a true value.
Solution
findElementById
should be
getElementById
Mozilla's documentation of the Document DOM object
Answered By - ikegami
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.