【问题标题】:Webdriver IO - Unable to find element with CSS selector with IDWebdriver IO - 无法找到带有 ID 的 CSS 选择器的元素
【发布时间】:2021-08-21 23:08:20
【问题描述】:

我正在使用以下语句编写一个简单的 WDIO 选择器。我能够在浏览器中唯一地识别它。不知道为什么 WDIO 无法设置该值。


Given(/^I am on the login page$/, function () {
    browser.url('https://secure-sandbox.modulrfinance.com/')
    browser.maximizeWindow()
});

When(/^I enter password as \"([^\"]*)\"$/, function (password:string) {
    //const txt_username = $('#username-inp')
    //const txt_password = $('#password-inp')
    $('#username-inp').setValue('')
    $('#password-inp').setValue(password)
});

Then(/^I should see a flash message under username saying \"([^\"]*)\"$/, async function () {
    const banner = await $('#.ng-star-inserted')
    expect(banner).toHaveText('This field is required1')
});```

**error**
**[0-0]   error: 'no such element',
[0-0]   message: 'no such element: Unable to locate element: {"method":"css selector","selector":"#password-inp"}\n'** +

【问题讨论】:

  • 你能为这个元素添加你的 DOM 细节吗?

标签: webdriver-io


【解决方案1】:

似乎您正在测试用angular 编写的Single Page Application。您必须通过添加适当的等待(ImplicitExplicitFluent 等待)来处理 Angular 的异步行为。

检查这个example

【讨论】:

    猜你喜欢
    • 2013-07-29
    • 2012-09-03
    • 2020-02-11
    • 2021-11-08
    • 2014-08-08
    • 2015-09-13
    • 2022-07-21
    • 1970-01-01
    • 2016-01-21
    相关资源
    最近更新 更多