Nightwatch无法找到/单击下拉选项 [英] Nightwatch Cannot Find/Click on Dropdown Option
问题描述
我既是背包客又是程序员,她试图利用第二种技能在一个完整的露营地中寻找空缺.我不是从头开始,而是使用端到端测试框架nightwatch.js为我导航.
I'm a backpacker and a programmer, trying to use the second skill to find openings in a full campsite. Rather than crawling fro scratch, I'm using the end-to-end testing framework nightwatch.js to navigate for me.
我遇到了障碍,因为守夜人很难使用css选择器找到特定的元素.
I've hit a roadblock, because nightwatch is having difficulty finding a specific element using css selectors.
我的测试代码将单击带有#permitTypeId
的选择框.它将看到#permitTypeId option
是可见的.指定更具体的值时,它将不查看或单击任何选项.五个.click()
都是我已经尝试过的CSS选择器.没有一个选项设置为display:hidden
或display:none
.我还尝试了上述所有操作,而没有.waitForElementToBeVisible()
,以防万一等待导致下拉菜单隐藏.
My test code will click on the selection box with #permitTypeId
. It will see that #permitTypeId option
is visible. It will not see or click on any of the options when more specific values are specified. The five .click()
's are all css selectors I've already tried. None of the options are set to display:hidden
or display:none
. I have also tried all of the above without the .waitForElementToBeVisible()
just in-case the waiting causes the dropdown to hide.
我已经成功单击了该网站上不同下拉菜单中的选项,没有任何问题.只是这引起了头疼.
I've successfully clicked options from different dropdown menus on this website without any problem. Just this one is causing a headache.
测试在Mac Yosemite上使用最新的Selenium服务器和Firefox运行.
The tests are running with the most current Selenium server and Firefox on Mac Yosemite.
Nightwatch.js/Selenium不会从下拉菜单中单击某些内容.
Nightwatch.js/Selenium won't click on something from a dropdown menu.
推荐答案
路径...
Cory让我考虑了jQuery和本机DOM操作.尝试过这条路线,并使用Selenium的.execute()
函数成功选择了正确的选项:
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')
但是,它没有触发onchange
事件.
However, it was not triggering the onchange
event.
看到此帖子这使我开始考虑使用按键和这一个建议使用箭头键将<select>
元素向下导航至该选项,然后按Enter.
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.
.click('select[id=permitTypeId]')
.keys(['\uE015', '\uE006'])
我发现这是Firefox的问题.单击<option>
标签,Chrome和PhantomJS可以很好地运行.
I've found that this is an issue with Firefox. Chrome and PhantomJS operate well clicking <option>
tags.
这篇关于Nightwatch无法找到/单击下拉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!