in reply to How to write in a non-form field of which the xpath is known using WWW::Mechanize::Chrome ?

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?

  • Comment on Re: 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^2: How to write in a non-form field of which the xpath is known using WWW::Mechanize::Chrome ?
by garo (Initiate) on Jan 09, 2026 at 11:00 UTC

    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', );