【问题标题】:NIghtwatch: I need to search for a word in a table without using document夜班:我需要在不使用文档的情况下在表格中搜索单词
【发布时间】:2017-11-13 22:26:03
【问题描述】:

我是使用 Nightwatch 的初学者,但遇到以下问题:

我有一张桌子,里面有一个<tbody> 和多个<tr>s。我需要检查特定单词是否在第一列的一个单元格中。

首先,我尝试使用 document.GetElements... 获取整个表,但 Nightwatch 似乎不支持此功能。目前,我正在寻找不使用 Nightwatch 自定义命令的解决方案。

附:我还不能创建标签,所以如果有人能创建一个标签会很棒,比如table-to-array 或类似的东西。

【问题讨论】:

标签: javascript node.js nightwatch.js getelementsbyclassname


【解决方案1】:

您可以使用execute 命令(Documentation here) 在浏览器中执行javascript 代码。所以你可以这样做:

client.execute(function(){
    /*your js to get the DOM element and check if the element has the text you want*/
    return true //or false if didnt find it
},[],function(response){
    console.log(response.value)//this will contain your returned value
    client.assert.equal(response.value, true, "Text not found on table")
})

【讨论】:

  • 谢谢!这是我为 js 代码写的: var tbs=document.getElementByTagName('tbody')[0].getElementByClassName('carrier-name'); for(var i=0; i
  • 您的断言中是否检查了response.value 值?回调函数接收其他数据作为参数(我不记得其他数据)。在value键处,就是你返回的数据
  • 这是我的整个 test.js:module.exports = { 'Test' : function (client) { client.execute(function(){ var tbs=document.getElementByTagName('tbody')[0 ].getElementByClassName('carrier-name'); for(let i=0; i
  • 不确定您到底在问我什么(正如我所说,我是初学者)。不知道response.value是什么类型。。按照我理解的方式,就是js函数中返回的(真假),不是吗?
  • 我在循环中添加了 console.log(tds[i].innerText) ,但是在控制台中,什么都没有写入......只有同样的错误:失败 [equal]:(错误)- 预期为“true”,但得到:“[object Object]”
猜你喜欢
  • 2023-03-23
  • 2017-03-07
  • 2019-12-13
  • 2021-04-19
  • 1970-01-01
  • 2015-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多