[英]How to select dropdown option with Casperjs and fillSelectors
我有以下表格:
<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>
但無法使用以下代碼選擇“訂戶”選項:
this.fillSelectors('form#security_page_toplevel_page_itsec_settings', {
'select[name="itsec_strong_passwords[roll]"]': 'subscriber'
}, true);
我究竟做錯了什么?
表單的名稱屬性與id屬性不同。
你要選擇的form
使用
this.fillSelectors('form[name="security_page_toplevel_page_itsec_settings"]', {
'select[name="itsec_strong_passwords[roll]"]': 'subscriber'
}, true);
如果這不起作用,則可以嘗試在頁面上下文中顯式設置select選項:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.