相关疑难解决方法(0)

尝试从Cypress中的元素获取属性时出错

我有这个HTML元素:

<input id="" type="text" name="last_name" value="Userc7bff2d0-7faf-11e8-9884-8fe4c5df7f77-Updated" class="medium" maxlength="2000" autocomplete="off" tabindex="" data-reactid=".0.2.0.1.0.2.1.0.1.0.0.1:0.1.0.1.2:$/=10">
Run Code Online (Sandbox Code Playgroud)

我想获得它的value属性来断言它已经通过我的测试进行了更新。

我尝试使用its()

cy
  .get(selector)
  .its("value")
  .should("contain", "-Updated");
Run Code Online (Sandbox Code Playgroud)

但是得到错误:

CypressError:超时重试:cy.its()错误,因为主题上的属性'value'不存在。

我也尝试过invoke

cy
  .get(selector)
  .invoke("value")
  .should("contain", "-Updated");
Run Code Online (Sandbox Code Playgroud)

但是得到一个类似的错误:

CypressError:超时重试:cy.invoke()错误,因为您的主题上不存在属性“ value”。

在这两种情况下,get()命令的Cypress控制台输出都会value成功显示具有其属性的元素:

产生:输入id =“” type =“ text” name =“名字” value =“伪更新” class =“ medium” maxlength =“ 2000” autocomplete =“ off” tabindex =“” data- reactid =“。0.2 .0.1.0.2.1.0.1.0.0.1:0.1.0.0.2:$ / = 10“

我有点为难。如果您需要更多信息或有什么想法请告诉我。

cypress

13
推荐指数
4
解决办法
9813
查看次数

标签 统计

cypress ×1