javascript - How to select dropdown option with Casperjs and fillSelectors - Stack Overflow

I have the following form:<form name="security_page_toplevel_page_itsec_settings" method=&

I have the following form:

<form name="security_page_toplevel_page_itsec_settings" method="post" action="options.php">
    <select id="itsec_strong_passwords_roll" name="itsec_strong_passwords[roll]">
        <option value="admin">admin</option>
        <option value="subscriber">subscriber</option>
    </select>
</form>

but I am unable to select the "subscriber" option with the following code:

this.fillSelectors('form#security_page_toplevel_page_itsec_settings', {
    'select[name="itsec_strong_passwords[roll]"]': 'subscriber'
}, true);

What am I doing wrong?

I have the following form:

<form name="security_page_toplevel_page_itsec_settings" method="post" action="options.php">
    <select id="itsec_strong_passwords_roll" name="itsec_strong_passwords[roll]">
        <option value="admin">admin</option>
        <option value="subscriber">subscriber</option>
    </select>
</form>

but I am unable to select the "subscriber" option with the following code:

this.fillSelectors('form#security_page_toplevel_page_itsec_settings', {
    'select[name="itsec_strong_passwords[roll]"]': 'subscriber'
}, true);

What am I doing wrong?

Share Improve this question edited Mar 29, 2016 at 19:18 Artjom B. 62k26 gold badges135 silver badges230 bronze badges asked May 8, 2014 at 17:09 SulliSulli 8671 gold badge14 silver badges39 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 5

The name attribute of the form is not the same as the id attribute.

You have to select the form using

this.fillSelectors('form[name="security_page_toplevel_page_itsec_settings"]', {
    'select[name="itsec_strong_passwords[roll]"]': 'subscriber'
}, true);

If this does not work, you could try explicitly setting the select option in the page context:

var index = 2; // the index to select, you may calculate the index programatically from the option value
this.evaluate(function(index) {
    var sel = document.querySelector('form[name="security_page_toplevel_page_itsec_settings"] select[name="itsec_strong_passwords[roll]"]');
    sel.selectedIndex = index;
    sel.onchange();
}, index);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744837515a4596353.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信