Cypress:如何在日志中显示td元素的文本值?

huangapple go评论52阅读模式
英文:

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)")))

html code

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)")))

html code

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);
  });

huangapple
  • 本文由 发表于 2023年5月25日 19:35:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76331824.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定