18

I want to set the value of a certain formless input field.

my $field = $w->selector('tr.edit td[data-attribute="name"] input', single => 1);

finds it.

$field->attributes->{value} = 'test';

has no apparent effect.

Both

$w->field($field => 'test');

and

$w->field('tr.edit td[data-attribute="name"] input' => 'test');

error out with No elements found for form number 1.

daxim
  • 39,270
  • 4
  • 65
  • 132

2 Answers2

5

When I ran into this problem, I would just use the eval method and let Javascript (or jQuery if it's loaded in the page) take care of selecting and setting values. For me it was mostly selecting drop-downs, where the Angular application on the page required a change or click event.

$mech->eval( q{$(tr.edit td[data-attribute="name"] input).val('test')} );

If there is no jQuery I am sure your Google fu will help you out.

simbabque
  • 53,749
  • 8
  • 73
  • 136
3

You maybe able to use something like below

$w->driver->send_message('DOM.setAttributeValue', nodeId => 0+$field->nodeId, name => 'value', value => "test" )->get

Reference from the actual source code

https://metacpan.org/source/CORION/WWW-Mechanize-Chrome-0.10/lib/WWW/Mechanize/Chrome.pm#L3137

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265