WebDriverio ReferenceError $未定义错误

发布于 2025-02-13 21:29:20 字数 1425 浏览 0 评论 0原文

我正在使用Appium使用WebDriverio编写一个简单的自动测试。我想访问Google.com,然后单击“登录”按钮。但是,我似乎无法使用 $ 选择器。这是我的代码:

const webdriverio = require('webdriverio');
const androidOptions = require('../../helpers/caps').androidWebOptions;
const assert = require('chai').assert;
 
describe('Create Chrome web session', function () {
  let client;
 
  before(async function () {
    client = await webdriverio.remote(androidOptions);
  });
 
  after(async function () {
    return await client.deleteSession();
  });
 
  it('should create and destroy Android browser session', async function () {
    // Navigate to google.com
    const client = await webdriverio.remote(androidOptions);
    await client.url('https://www.google.com');
 
    const title = await client.getTitle();
 
    $('#4ca7df34-c02a-4b70-8318-8382f2318a4a').click()
 
    assert.equal(title, 'Google');
  });
});

我一直遇到无法使用美元符号选择器的错误。我尝试在此处重新编写文档: http://appium.io/docs /en/commands/element/actions/click/

清楚地表明您必须使用美元符号选择器才能单击在元素上通过ID。

我确保注意我使用的ID是正确的,并将ID更改为屏幕上的另一个对象产生了相同的结果。

方案: referenceError:$ nordin(webdriverio)

我还尝试了此解决 我是无效的选择器错误。

任何帮助将不胜感激。

I'm using Appium to write a simple automated test with WebDriverIO. I want to visit Google.com, and click on the sign in button. However, I can't seem to be able to use the $ selector. Here's my code:

const webdriverio = require('webdriverio');
const androidOptions = require('../../helpers/caps').androidWebOptions;
const assert = require('chai').assert;
 
describe('Create Chrome web session', function () {
  let client;
 
  before(async function () {
    client = await webdriverio.remote(androidOptions);
  });
 
  after(async function () {
    return await client.deleteSession();
  });
 
  it('should create and destroy Android browser session', async function () {
    // Navigate to google.com
    const client = await webdriverio.remote(androidOptions);
    await client.url('https://www.google.com');
 
    const title = await client.getTitle();
 
    $('#4ca7df34-c02a-4b70-8318-8382f2318a4a').click()
 
    assert.equal(title, 'Google');
  });
});

I keep getting the error that the Dollar sign selector can't be used. I tried reffering tot he documentation here: http://appium.io/docs/en/commands/element/actions/click/

Which clearly shows that you have to use the dollar sign selector in order to click on an element via ID.

I made sure to note the ID I used was correct and changing the ID to another object on the screen yielded the same results.

I also tried this solution: ReferenceError: $ is not defined (WebdriverIO)

But that gives me an invalid selector error.

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡的优雅 2025-02-20 21:29:20

您可以尝试以下代码。

client.$('#4ca7df34-c02a-4b70-8318-8382f2318a4a').click()

Can you tried with below code.

client.$('#4ca7df34-c02a-4b70-8318-8382f2318a4a').click()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文