本文介绍了Nightwatch中的setValue方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个新的Nightwatch项目,以实现简单的Google搜索页面的自动化.我对页面上出现的 searchbox 的断言通过了,但是我无法对元素(SearchboxSearchButton)

I am trying to setup a new Nightwatch project for the purpose of automating a simple Google search page. My assert for searchbox present on page passes, but I am not able to perform any mouse/keyboard action on the elements (Searchbox, or SearchButton)

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

Note: I am running Nightwatch version 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进行演示测试

Running: Demo test Google

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

错误日志:

TimeoutError:运行.setValue()命令时发生错误 于:{状态":-1, 状态":"", 价值": {"message":未知错误:调用函数结果缺少'value'", "error":[(会话信息:chrome = 77.0.3865.120)",(驱动程序信息:chromedriver = 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),平台= Windows NT 10.0.17763 x86_64)]}," errorStatus:13," error:"未知错误:调用函数结果缺少'value'," httpStatusCode:200} 在process._tickCallback(内部/进程/next_tick.js:68:7)处NoSuchElementError:运行.click()命令时发生错误 在 : 在process._tickCallback(internal/process/next_tick.js:68:7)

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)

推荐答案

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

Try to click() on input first, and then use setValue(), sometimes it helps

这篇关于Nightwatch中的setValue方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 21:27