Nightwatch Cannot Find/Click on Dropdown Option

不打扰是莪最后的温柔 提交于 2019-12-01 03:43:36
Adam

The Path...

Cory got me thinking about jQuery and native DOM manipulation. Tried going that route and was successful selecting the correct option using Selenium's .execute() function:

.execute('document.getElementById("permitTypeId").options[1].selected=true')

However, it was not triggering the onchange event.

Saw this post which made me start thinking about using key-strokes and this one which suggested using arrow-keys to navigate down a <select> element to the option, then hitting enter.

...to the Solution

.click('select[id=permitTypeId]')
.keys(['\uE015', '\uE006'])

I've found that this is an issue with Firefox. Chrome and PhantomJS operate well clicking <option> tags.

Gokul Muralidharan

you should be able to click like this way

browser.click('select[id="permitTypeId"] option[value="1451140610"]')

Additionally I was able to add a .click event for the specific option once I did a .click for the select. see my example below:

.click('select[name="timezone"]') 
.pause(1000)
.click('option[value="America/Chicago"]') //selects the option but doesn't click
.pause(5000)
.keys(['\uE006']) //hits the enter key.

another solution:

  .click('select[id="permitTypeId"]')
  .waitForElementVisible("option[value='1451140610']")
  .click("option[value='1451140610']")

Very simple way is to use .setValue('@element', 'value of option')

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