david-dick / firefox-marionette

This is a client module to automate the Mozilla Firefox browser via the Marionette protocol
https://metacpan.org/dist/Firefox-Marionette
Other
12 stars 3 forks source link

JSON serialization error when providing DOM elements to script() #2

Closed eserte closed 3 years ago

eserte commented 3 years ago

It is not possible to provide previously found DOM elements as arguments to a script() method call:

$ perl -MFirefox::Marionette -E '$fm = Firefox::Marionette->new->go(shift); $body = $fm->find("//body"); say $fm->script(q{ return arguments[0].outerHTML;}, args => [$body]);' http://www.example.org 
encountered object 'Firefox::Marionette::Element=HASH(0x5612655ec8a8)', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing) at /opt/perl-5.30.3/lib/site_perl/5.30.3/Firefox/Marionette.pm line 6842.

After some experiments and research I found a working solution:

$ perl -MFirefox::Marionette -E '$fm = Firefox::Marionette->new->go(shift); $body = $fm->find("//body"); say $fm->script(q{ return arguments[0].outerHTML;}, args => [{"element-6066-11e4-a52e-4f735466cecf" => $body->uuid}]);' http://www.example.org
<body>
<div>
...

(The magic key I got from https://www.w3.org/TR/webdriver/#dfn-web-element-identifier)

Maybe the JSON serialization needs to be adapted here?

david-dick commented 3 years ago

Thanks for the report. Committing a fix.