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

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

问题描述

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

似乎无论我使用什么方法与选择框交互,在 safari 上都不起作用.我仅用于 chrome 的选项在 chrome 浏览器上仍然可以正常工作,但我们希望启动并运行我们的 safari 集成测试.

适用于 chrome 的选项是:

<块引用>

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

然而,这使得选择器在 safari 上点击但没有选择任何选项,打破了我们需要选择的表单.

我试过连续点击两个像

<块引用>

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

使用按键:

<块引用>

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

包装在执行调用中:

<块引用>

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

以及我能想到的每一种组合.

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

注意:我也尝试过查看执行此操作的通用硒方式,并使用 .execute('insert javascript to change value of select element') 但这不会触发 onchange 事件和表单反正不提交.

如果我在本地手动拦截测试并在自动化打开选择框后单击选择选项它工作正常,我只需要一种在打开后导航到或单击该选项的方法.

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

解决方案

可能有效的是获取您正在寻找的 的可见文本,并将其用作setValue().这适用于我的 Chrome 浏览器:

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

选项 2:

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

var select = document.querySelector('select[name="elementName"]'),option = select.querySelector('option.OptionClass');select.value = option.value;select.dispatchEvent(new Event("change", { bubbles: true }));

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.

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.

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')

using keystrokes:

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

wrapping in perform calls:

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

And about every combination in between I can think of.

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?

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.

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

解决方案

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);
  })

Option 2:

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天全站免登陆