首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >selenium-server不会“`setValue`”

selenium-server不会“`setValue`”
EN

Stack Overflow用户
提问于 2018-03-22 02:46:04
回答 2查看 920关注 0票数 1

我在节点8.9.0上使用selenium-server版本3.0.1和nightwatch版本^0.9.12。我的e2e测试确实运行、单击work和读取DOM工作,但setValue就是没有。

例如,以下测试:

代码语言:javascript
复制
browser
  .url("...")

  .waitForElementPresent('select[name=foo]', 5000)
  .click('select[name=foo] option:nth-child(2)')

  .waitForElementPresent('input[name=bar]', 5000)
  .setValue('input[name=bar]', "hello world")
  .getValue('input[name=bar]', function(input) {
    this.assert.equal(input.value, "hello world");
  })

  .end();

将打开url,等待foo并单击第二个选项。它将等待bar,然后失败:

代码语言:javascript
复制
Running: test
 ✔ Element <select[name=foo]> was present after 24 milliseconds.
 ✔ Element <input[name=bar]> was present after 28 milliseconds.
 ✖ Failed [equal]: ('' == 'hello world')  - expected "hello world" but got: ""
    at Object.<anonymous> (/test/e2e/specs/test.js:49:21)


FAILED:  1 assertions failed and 2 passed (4.692s)

 _________________________________________________

 TEST FAILURE:  1 assertions failed, 2 passed. (4.9s)

 ✖ test

   - run through apply process (4.692s)
   Failed [equal]: ('' == 'hello world')  - expected "hello world" but got: ""

如果我用延迟替换setValue并手动输入一个值,测试就会通过,所以getValue正在工作。

这确实会在其他系统上运行和传递,但是我无法让它自己工作,所以我认为这是一个selenium-server问题。

我已经尝试过许多101个修复,清除npm缓存,重新运行npm install等等。但是除了失败之外,没有其他错误,我如何调试呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-22 11:41:21

假设您正在尝试使用Chrome进行测试,则需要更新您的ChromeDriver。Chrome 65是最近发布的,较早的ChromeDriver版本显然与它不兼容。

下载页面下载最新版本。

让夜莺使用它,nightwatch.json -

代码语言:javascript
复制
{
...
    "selenium": {
...
        "cli_args": {
            "webdriver.chrome.driver": "path/to/chromedriver.exe"

假设Nightwatch使用它(您可以看到它使用Windows (假设您使用的是Windows )--查找chromedriver.exe的命令行),setValue现在应该再次工作。

票数 1
EN

Stack Overflow用户

发布于 2018-03-22 06:56:38

这个错误说明了一切:

代码语言:javascript
复制
Failed [equal]: ('' == 'hello world')  - expected "hello world" but got: ""

在您的代码块中,您已经为标识为'inputname=bar'的WebElement和下一个调用的setValue()导出了wait,成功的如下所示:

代码语言:javascript
复制
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")

现在,与此'inputname=bar'相关联的JavaScript将需要一些时间来呈现HTML中的值。但是,在代码块中,您试图过早地访问输入的值(在上一步中)。因此,您的脚本找到<null>作为值。

解决方案

您需要为HTML中的值通过关联的期望导入一个JavaScript子句,如下所示:

代码语言:javascript
复制
.waitForElementPresent('input[name=bar]', 5000)
.setValue('input[name=bar]', "hello world")
.expect.element('input[name=bar]').to.have.value.that.equals('hello world');
.getValue('input[name=bar]', function(input) {
  this.assert.equal(input.value, "hello world");
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49419706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档