英文:
Cypress: How to display text value of a td element in the log?
问题
I want given td value and display on the log without understanding text value to Cypress. (dynamic)
I have written the below code but it can't return text value.
cy.log((cy.get("tr td:nth-child(5)")))
tttttttttttttttttttttttttttttttttttttttttttttttttttt
英文:
i want given td value and display on the log without undrestude text value to cypress.(dynamic)
i wriiten the below code but it can't return text value.
cy.log((cy.get("tr td:nth-child(5)")))
tttttttttttttttttttttttttttttttttttttttttttttttttttt
答案1
得分: -1
cy.get('tr td:nth-child(5)')
返回一个Chainable<JQueryElement>
类型的对象,并不是返回元素的文本内容。要正确记录或操作该文本值,您需要在cy.get()
命令后进行链式操作。
cy.get('tr td:nth-child(5)').then(($el) => {
cy.log($el.text()); // 使用JQuery的`.text()`命令
});
// 或者
cy.get('tr td:nth-child(5)')
.invoke('text') // 调用text属性
.then((text) => {
cy.log(text);
});
英文:
cy.get('tr td:nth-child(5)')
yields a Chainable<JQueryElement>
type object, and not the text of the element yielded. In order to properly log or manipulate that text value, you'll have to chain off of the cy.get()
command.
cy.get('tr td:nth-child(5)').then(($el) => {
cy.log($el.text()); // use the JQuery `.text()` command
});
// or
cy.get('tr td:nth-child(5)')
.invoke('text') // invoke the text attribute
.then((text) => {
cy.log(text);
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论