我想通过Perl& amp;设置输入元素的value属性。像这样的硒:
pl
哪个工作正常,我在屏幕上看到了新值,除了" onchange"事件不会以这种方式解雇。我尝试过这样的事情:
my $script = q{
arguments[0].setAttribute(arguments[1], arguments[2]);
};
$driver->execute_script($script, $element, $attribut, $new_value);
但没有任何反应。
答案 0 :(得分:0)
这是我的解决方案(在Perl中):
sub fire_event {
my $element = shift // croak("Which element should be used to fire the even?");
my $event = shift // croak("Which event should be fired");
my $script;
if($browser eq "internet explorer") {
$script .= "var evt = document.createEventObject();";
$script .= "return arguments[0].fireEvent('on'+".$event.",evt);";
}
else {
$script .= 'var evt = document.createEvent("HTMLEvents");'."\n";;
$script .= "evt.initEvent('". $event ."', true, true );\n";
$script .= "return !arguments[0].dispatchEvent(evt);\n";
}
my $rc = $driver->execute_script($script, $element);
return $rc
}
my $returncode = fire_event($elem, "submit");