javascript - 无法使用 cypress 访问 html 元素
问题描述
我正在尝试使用 cypress 测试登录功能,但由于某种原因,我无法访问输入文本框。它显示 Timed out retrying after 4000ms: Expected to find element: runner container,但从未找到它。
describe("User authentication", () => {
beforeEach(() => {
cy.visit("https://lmflf.com");
});
it("it takes to the correct page", () => {
cy.get('[data-field=password]')
});
});
解决方案
我可以在您的网页中看到一个影子 DOM,在这种情况下您必须使用.shadow()
( Cypress Docs )。您的代码将类似于:
cy.get('view-login').shadow().find('input[data-field="username"]').type('username', {force: true})
cy.get('view-login').shadow().find('input[data-field="password"]').type('password', {force: true})
cy.get('view-login').shadow().find('input[value="personal"]').click()
cy.get('view-login').shadow().find('.ViewLogin__button').click()
推荐阅读
- automated-tests - Codefresh 魅力报告:测试报告者需要 CF_BRANCH_TAG_NORMALIZED 变量来上传文件
- sql-server - 计算足球运动员之间互动的统计数据
- jquery - 使用 jQuery、Ajax ASP.NET 的 MVC 模态登录
- android - Android Studio 3.4、4.1 无法在 windows 7 上启动 adb
- javascript - 没有嵌套循环的两个数组之间的检查和匹配?
- python - 有谁知道如何解决这个问题?“ TypeError:需要一个类似字节的对象,而不是'int'”
- php - 显示“on”而不是实际值的单选按钮
- javascript - 如何从 php 获取 javascript 中的 id 以显示数据
- javascript - 使用 tab 键时如何正确设置项目的焦点顺序
- http - 谷歌驱动 GET 请求,无需手动登录