javascript - 用柏树找不到 iframe
问题描述
我试图让柏树找到我的 iframe。我发现了一个 GitHub 问题,它讨论了关于 iframe 的 cypress 限制的变通方法,这就是我采用的解决方案。
Cypress.Commands.add('iframe', { prevSubject: 'element' }, $iframe => {
return new Cypress.Promise(resolve => {
$iframe.on('load', () => {
resolve($iframe.contents().find('body'));
});
});
});
这是我实际使用此命令的地方。
context("Basic simple test", () => {
it("can visit our app", () => {
cy.visit("http://localhost:3000");
cy.get('#haha').iframe();
})
})
这是我的 iframe 代码。
<StyledFrame
sandbox="allow-forms allow-scripts allow-same-origin allow-modals allow-popups allow-presentation"
title="sandbox"
id="hahah"
srcDoc={this.state.isLoading ? loader : this.state.bundle}
/>
然而,赛普拉斯告诉我它找不到 id 为haha
.
解决方案
这可能只是因为您要查找的 id 是 #haha 而 iframe 的 id 是 hahah (带有额外的 h )。尽管不能保证您不会不小心拼错 id,但我建议您使用更具描述性的名称,这样它就不太可能发生。
推荐阅读
- sqlite - 唯一约束失败的sqlite
- c# - 用户未登录时如何显示登录链接?
- bayesian - PyMC3 sample() 函数不接受“开始”值来生成跟踪
- python - 获取循环中理解列表生成的乘法列表中的值的总和
- google-cloud-platform - Firebase函数与同一VPC中的GCP Redis实例的连接不断断开
- python - Python:进程以退出代码 -1073741819 (0xC0000005) 结束。如何调试?
- c++ - C++ unordered_set 和 set 上的 set_intersection 方法的结果不一致
- javascript - Javascript模式仅在单击按钮时才起作用
- r - R:如何在命名向量中切片元素窗口
- php - 通过 php 将新元素添加到 MySQL 查询的结果中