【问题标题】:what is $$ and $ in webdriver and how to use it in JS applications?webdriver 中的 $$ 和 $ 是什么以及如何在 JS 应用程序中使用它?
【发布时间】:2018-07-09 00:10:08
【问题描述】:

根据 webdriver 文档
With the $ and $$ functions WebdriverIO provides useful shortcuts which can also be chained in order to move deeper in the DOM tree without using complex xPath selectors.

但在这里我正在尝试使用 web 驱动程序和 chai 为我的 reactjs 和 flowjs 应用程序编写 cucumber 测试, 我有这样的用户界面,我需要使用按钮文本/值来测试所有按钮的存在。这是设计

这是我尝试过的

const links = $$('.button').filter(function(link) {
  return link.isVisible();
});
const button1_value = links[0].getText();
const button2_value = links[1].getText();
expect(button1_value).to.equal('button1');
expect(button2_value).to.equal('button2');

但我收到$$ 的以下错误,

有没有其他方法可以获取按钮列表并进行测试。

我是否必须导入 $$$ 才能在 js 文件中使用。

【问题讨论】:

  • 您确定您的 WebdriverIO 安装正确吗?

标签: javascript selenium selenium-webdriver webdriver cucumber


【解决方案1】:

知道了,我们可以使用$$$browser

例如:const links = await browser.$$(selector);

但是为了获取按钮的内容/值,我遵循了这个。

const links = await browser.getText('.button');
expect(links[0]).to.equal('button1');
expect(links[1]).to.equal('button2');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 2017-01-21
    • 2016-12-23
    • 2011-08-27
    • 2013-04-24
    • 2021-07-23
    相关资源
    最近更新 更多