简体   繁体   中英

Using Dalekjs test tool, how to select Option in Dropdown(Select element) when there is no “value” attribute in Option tag?

Lets consider below "Select" example with "value" attribute,

<select onchange="fruitSelected();" id="">
<option value=""></option>
<option value="apple">apple</option>
<option value="mango">mango</option>
<option value="banana">banana</option>
</select>

Using dalekjs I'm able to select the option using below code,

.click('#moduleType option[value="apple"]')

But, when the above example don't have "value" attribute as show below,

<select onchange="fruitSelected();" id="fruitID">
<option></option>
<option>apple</option>
<option>mango</option>
<option>banana</option>
</select>;

How to select option from dropdown?

I tried using .execute as below,

.execute(function () {
    document.getElementById("fruitID").selectedIndex = "1";
})

I'm able to select option as apple, but onchange function is not getting called.

How to select option from dropdown? so that onchange function also can b called.

NOTE: Select tag cannot be modified, as I'm just testing.

Thanks in Advance..

我做了更多的研发工作,发现上述情况可以通过使用.setvalue()来解决,如下所示

.setValue('#fruitID','apple')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM