Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set the value of an input field by complex selector?

  • WWW::Mechanize::Chrome 0.10
  • Iridium 2017.11 in a headed desktop session

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.

like image 988
daxim Avatar asked Mar 19 '18 13:03

daxim


1 Answers

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.

like image 79
simbabque Avatar answered Nov 15 '22 20:11

simbabque