webdriver.io 选择多个元素并一一单击

webdriver.io selecting multiple elements and clicking one by one

我正在使用 webdriver.io 进行一些自动化单元测试,我可以 select 使用 browser.elements

多个元素

但我需要能够点击每个 selected 元素

我知道有一个 browser.click() - 但它只会点击第一个元素 我已经玩了 3 个小时了 - 关于 webdriver.io 关于使用 browser.elements

的文档有点令人困惑

如何触发每个 selected 元素的点击?

var selector = '.main-section * .tbody .td:nth-child(14) a';
// this gets an awway of element id's   
var selectedButtons = browser.elements(selector);

// log returned array
console.log(selectedButtons.value);
// this prints the elementId's
console.log(selectedButtons.value[1].element().value.ELEMENT);

输出:

 [ { ELEMENT: '0.23250146411810424-135',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-135' },
    index: 0 },
  { ELEMENT: '0.23250146411810424-136',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-136' },
    index: 1 },
  { ELEMENT: '0.23250146411810424-137',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-137' },
    index: 2 },
  { ELEMENT: '0.23250146411810424-138',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-138' },
    index: 3 } ]

0.23250146411810424-136

在黑猩猩中使用 webdriver.io

最新版本的 webdriver-sync 添加了功能,以便返回的元素具有 webdriver.io 原型 - 也就是说,您可以对数组中的返回元素调用 .click .

版本 0.45.x+ 的黑猩猩使用最新的 webdriver-sync