如何在其他非cypres函数中使用HTML元素中的文本?
我需要从HTML元素中获取文本以在其他检查中使用它。
但是,此检查必须在其他地方进行,而不是文本获取的内部功能。
这就是为什么
> cy.get('#at__title').invoke('text').then((storedValue) => {
> storedValue
> })
不适合套件的变体的原因,因为我只能在然后
中使用文本。
我也尝试使用
> cy.get('#at__title').invoke('text').as('element_text')
> this.element_text
,但控制台日志显示this.element_text
undefined。
I need to get text from html element to use it in other checking.
But this checking must be done elsewhere later, not inside function of text getting.
That's why such variant as
> cy.get('#at__title').invoke('text').then((storedValue) => {
> storedValue
> })
doesn't suite, because I can use text only inside then
.
Also I tried to use
> cy.get('#at__title').invoke('text').as('element_text')
> this.element_text
but console log shows this.element_text
as undefined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用别名是正确的
cy.get('#at __title')。indoke('text')。as('element_text')
,但要访问这样的值,就需要测试对 <> <强>不是 是箭头函数。
使用此格式
或使用较长的语法访问别名
Using an alias is correct
cy.get('#at__title').invoke('text').as('element_text')
but to access the value like thisrequires the test to not be an arrow function.
Use this format
Or use the longer syntax for accessing an alias