如何解决通过 webdriver.io 版本 7 访问 shadowElements
当 item
与当前注释掉的行一样求值时,以下代码运行良好,但 shadow-root 关联行因以下原因而失败:browser.$(...).shadow$ is not a function
。有什么迹象可以说明为什么会这样吗?
const LoginPage = require('../pageobjects/login.page');
const SecurePage = require('../pageobjects/secure.page');
describe('My Login application',() => {
it('should login with valid credentials',async () => {
await browser.url(`https://our-site/`);
// const item = await browser.$('body > cs-app')
const item = await browser.$('body > cs-app').shadow$('#page > login-page');
await expect(item).toBeExisting();
});
});
解决方法
您可以尝试将其运行为:
const item = await (await $('body > cs-app')).shadow$('#page > login-page');
正在修复中,不需要这个额外的“await”语句,但它还没有发布。你可以在这里查看: https://github.com/webdriverio/webdriverio/pull/6954
,扩展凯文回答的逻辑,我能够像这样钻透阴影层:
const item = await (await (await $('body > cs-app')).shadow$('#page > login-page')).shadow$('#username');
console.log('result --------------------',await (item.getAttribute('label'))) // Username
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。