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

I use WWW::Mechanize::Chrome but I can't manage to write in a <input>-field that's not inside a form.
According to the docs I need the set_field() method. Maybe it also works with the get_set_value() method but I have no idea here either...

If we assume that the only thing I know about the input-field is that it has the attribute id="foo" and that their is only one of these fields, how can I do this ?
The only progress I made so far is that I managed to create a WWW::Mechanize::Chrome::Node object with $node = $mech->xpath('//input[@id="foo"]', single => 1);

  • Comment on How to write in a non-form field of which the xpath is known using WWW::Mechanize::Chrome ?
  • Select or Download Code

Replies are listed 'Best First'.
Re: How to write in a non-form field of which the xpath is known using WWW::Mechanize::Chrome ?
by Corion (Patriarch) on Jan 08, 2026 at 08:23 UTC

    The documentation says the following about ->set_field:

    $mech->set_field( %options )
    $mech->set_field( field => $field_node, value => 'foo', );
    Low level value setting method. Use this if you have an input element outside of a <form> tag.

    What would make the usage more clear and help you to find out how to use ->set_field?

      I did RTFM, (which you literally copied).
      But I don't see how I can go from a xpath to a field node.

      Can you give me some example-code ?
      e.g. Let's assume the webpage is <html><body><input id="foo"></input></body></html> and you want to fill it with bar.
      (But you have to use the xpath to find the input field because real pages will be way more complex)

        Corion not only copied the extract from the documentation, as the author of WWW::Mechanize::Chrome he wrote it, and asked you how it could be altered to make its use clearer. Since you already know how to find the element you want to change, simply do what the documentation states in the example provided and set the value:

        my ($node) = $mech->xpath('//input[@id="foo"]'); $mech->set_field( field => $node, value => 'Your value here', );