无法使用 $$ 登录 WebdriverIO 与元素交互

Unable to interact with elments using $$ sign in WebdriverIO

我正在使用 WebdrivreIO(v7),但无法从另一个文件导出 $$ 值。如果我正在使用同一个文件,它工作正常,但另一个文件不工作。不确定这里有什么问题

sample.js

module.exports = {
details: $$('.agent-rows p.name'),
}

script_file.js

When("Getting the list from the listing page"){
    const sample=require("./sample.js");
    console.log("value 1"+ await sample.details) // Output : nothing empty
    console.log("value 2"+ await sample.details[0]) // Output : undefined
}

你好像打错了s。应该是 sample.detail 而不是 sample.details.

When("Getting the list from the listing page"){
    const sample=require("./sample.js");
    console.log("value 1"+ await sample.detail) // 'detail' not 'details'
}

您确定您没有在常量样本 console.log 行之间做任何事情吗? require 一调用就会触发详情属性 .

因此,如果您正在尝试以下操作,它不会起作用

const elem = sample.details
//do something for the element to be present
(await elem)[0].dosomething

因为 sample.details 将在元素出现之前触发提取过程。 await 用于等待异步进程完成,而不是触发它。

改用:

  module.exports = {
         details: ()=>{$$('.agent-rows p.name')},
   }

在代码中:

const elem = sample.details
//do something for the element to be present
(await elem())[0].dosomething  //here you are triggering the fetch