如何解决在Cypress.io中,我可以从一个元素复制内容并将其粘贴到另一个元素例如,转换为表单吗?
我已经检查了Cypress.io常见问题解答:https://docs.cypress.io/faq/questions/using-cypress-faq.html#How-do-I-get-an-element%E2%80%99s-text-contents
这些技巧让我自己尝试了,但是失败了。
我想获取一个元素,获取它的内容,将其放入变量中,然后再使用。
我想获得与Selenium element.getText()类似的结果。
describe("Training Test Room Suite",() => {
it("Copy content from an element and past it into next one",() => {
let contentText
cy.visit("http://the-internet.herokuapp.com/login");
cy.get(".example > h2").should(($h2) => {
contentText = $h2.text()
})
cy.get("#username").type(contentText);
})
})
CypressError: cy.type()只能接受字符串或数字。您传入了:未定义
在上面的代码中,我试图从H2复制文本,将其放入变量contentText,然后将其粘贴到输入“用户名”中。演示应用程序http://the-internet.herokuapp.com/login
上的所有内容有人可以帮我吗:)
解决方法
我认为这是一个关闭问题。试试这个:
it("Copy content from an element and past it into next one",() => {
let contentText
cy.visit("http://the-internet.herokuapp.com/login");
cy.get(".example > h2").should(($h2) => {
contentText = Cypress.$($h2).text();
return contentText;
})
.then(() => {
cy.get("#username").type(contentText);
});
});
在此处查看文档:{{3}}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。