Nightwatch集成测试:无法从Safari中的选择下拉列表中选择选项 [英] Nightwatch integration test: Can't select option from select dropdown in Safari

查看:325
本文介绍了Nightwatch集成测试:无法从Safari中的选择下拉列表中选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了其他帖子并尝试了一些建议(例如 Nightwatch找不到/点击下拉菜单选项" Nightwatch从选择框中选择选项),但没有成功.

I've already read other posts and tried suggestions (eg Nightwatch Cannot Find/Click on Dropdown Option and Nightwatch to select option from select box) with no success.

看来,无论我使用哪种方法与选择框进行交互,Safari上都无用.我仅用于chrome的选项在chrome浏览器上仍然可以正常使用,但我们希望启动并运行safari集成测试.

It seems that regardless of what method I use to interact with a select box, nothing works on safari. The option I used for just chrome still works fine on chrome browser, but we're looking to get our safari integration tests up and running.

适用于chrome的选项是:

The option that works on chrome is:

.click('select[name="elementName"] option.OptionClass')

但是,这会使选择器在野生动物园中单击,但没有选择任何选项,从而破坏了需要选择的表单.

However this leaves the selector clicked on safari but no option selected, breaking our forms that require a selection.

我尝试了连续点击两次,

I've tried clicking both in succession like

.click('select[name="elementName"]') 
.click(' option.OptionClass')

使用击键:

.click('select[name="elementName"]')
.keys(['\uE015', '\uE006'])

包装表演电话:

browser.perform(function() {
  browser
    .click('select[id=element-id]')
    .click('option.className');
});

我能想到的几乎所有组合.

And about every combination in between I can think of.

到目前为止,关于守夜人问题,Google组或stackoverflow中的任何内容都没有帮助.有没有人遇到过这个问题,有没有人想出解决方案?

Nothing on nightwatch issues, google groups, or here in stackoverflow has helped so far. Has anyone encountered this issue and has anyone figured out a solution?

注意:我也尝试过寻找一种通用的硒方法,并使用.execute('insert javascript来更改select元素的值'),但这不会触发onchange事件和表单无论如何都不会提交.

Note: I've tried looking at a generic selenium way of doing this as well, and using the .execute('insert javascript to change value of select element') but that doesn't trigger the onchange event and the form doesn't submit anyways.

如果我在本地手动拦截测试并在自动打开选择框后点击选择选项,则它可以正常工作,我只需要一种方法即可浏览至该选项,或者在选择打开后单击该选项.

If I manually intercept the test locally and click on the select option after the automation has opened the select box it works fine, I just need a way to navigate to and or click the option after it's open.

我为此花费了大约2-3天的时间,因此非常感谢您的帮助.谢谢!

I've sunk about 2-3 days of work into this, so any help is extremely appreciated. Thanks!

推荐答案

可行的方法是获取要查找的<option>的可见文本,并将其用作setValue()的参数.这对于我的Chrome浏览器来说很好用:

What may work is to get visible text of the <option> you are looking for, and use it as a parameter for setValue(). This works fine for my Chrome browser:

browser
  .getText('select[name="elementName"] option.OptionClass', function(result) {
    client.setValue('select[name="elementName"]', result.value);
  })

选项2:

您还可以尝试使用execute()运行JavaScript并以编程方式设置值,然后在select元素上触发更改事件:

You can also try to run JavaScript with execute() and set value programmatically, then fire change event on your select element:

var select = document.querySelector('select[name="elementName"]'),
    option = select.querySelector('option.OptionClass');

select.value = option.value;
select.dispatchEvent(new Event("change", { bubbles: true }));

这篇关于Nightwatch集成测试:无法从Safari中的选择下拉列表中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆