admin管理员组

文章数量:1404579

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

本文标签: javascriptHow to select dropdown option with Casperjs and fillSelectorsStack Overflow