Nightwatch to select option from select box

…衆ロ難τιáo~ 提交于 2019-11-28 07:36:04

According to this post, this works:

.click('#myselectbox option[value=somevalue]')

The following syntax seems to be more reliable:

.click('select[id="myselectbox"] option[value="somevalue"]')

You may try the following, it works for me.

<option value="2">2</option>
...
.setValue('select[id="day"]','2')

if you have different value than the text in your option

e.g. <option value="123">abc</option>

You do .setValue ('select[id="yourselectid"]','abc')

If you want to do with Page Object, you have to use callback.

sectionInfo.click("@selectOwner",()=>{
  sectionInfo.click("option[value='owner']");
});
Dylan
.click("#selectid option:nth-child(1)")

This also works using class identifier -

e.g.

.click(".selectclass option:nth-child(1)")

Setting the nth-child to 1 will choose the first item in the dropdown.

Setting to 2 will select the second value, etc. etc.

Hope this helps for those of you who had no luck with previously stated solutions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!