gpt4 book ai didi

javascript - Nightwatch 中的 setValue 方法不起作用

转载 作者:行者123 更新时间:2023-11-28 03:28:14 25 4
gpt4 key购买 nike

我正在尝试设置一个新的 Nightwatch 项目,以便实现简单的 Google 搜索页面的自动化。我对页面上存在的搜索框的断言通过了,但我无法对元素(SearchboxSearchButton)执行任何鼠标/键盘操作)

注意:我正在运行 Nightwatch 版本 1.0

测试用例:

module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com') // Go to a url
.waitForElementVisible('body', 10000) // wait till page loads
.pause(2000)
.assert.title('Google') // Make sure Site title matches
.assert.visible('input[name=q]')
.setValue('input[name=q]', 'nightwatchjs') // send values
.click('button[name=btnG]') // click on search box
.pause(1000)
.end()
},
};

我也尝试过这种方法:

var setValue =  function(sel, value) {
$(sel).val(value).change();
};
module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com') // Go to a url
.waitForElementVisible('body', 10000) // wait till page loads
.pause(2000)
.assert.title('Google') // Make sure Site title matches
.assert.visible('input[name=q]')
.execute(setValue, ['input[name=q]', 'nightwatchjs'])
.click('button[name=btnG]') // click on search box
.pause(1000)
.end()
},
};

这是输出日志:

[Google] 测试套件

运行:演示测试 Google

  • √ 元素在 133 毫秒后可见。
  • √ 测试页面标题是否等于“Google” - 18 毫秒。
  • √ 测试元素是否可见 - 61 毫秒。

错误日志:

Error while running .setElementValue() protocol action: unknown error: call function result missing 'value'

TimeoutError: An error occurred while running .setValue() command on : {"status":-1, "state":"", "value": {"message":"unknown error: call function result missing 'value'", "error":[" (Session info: chrome=77.0.3865.120)"," (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17763 x86_64)"]},"errorStatus":13,"error":"unknown error: call function result missing 'value'","httpStatusCode":200} at process._tickCallback (internal/process/next_tick.js:68:7) NoSuchElementError: An error occurred while running .click() command on : at process._tickCallback (internal/process/next_tick.js:68:7)

最佳答案

尝试先在输入上单击(),然后使用setValue(),有时会有帮助

关于javascript - Nightwatch 中的 setValue 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58437187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com