首页 > 解决方案 > 从输入字段获取文本返回对象值而不是文本值

问题描述

我在做最简单的事情时遇到问题:验证字段中的值。

标记:

<input class="hb-inputfelt data-e2e-selector="boligbetegnelse" ng-reflect-form="[object Object]" id="finansieringsobjekt-boligbetegnelse-211-H01-0">

柏:

.should('have.text', 'value');

或者

.should('have.value', '123'):

返回

expected '<div>' to have value '123', but the value was ''

.should('have.text', '123');

返回

expected '<div>' to have text '123', but the text was 
  'a bunch of text - probably values from the object in ng-reflect-from=[object Object]

我猜问题出在字段中的对象,因为它返回的数据由来自前端“后面”对象的一长串对象值组成。

但我正在检查的值 - “123” - 是该字段中的可见文本。当上述方法不起作用时,我该如何获得它?

标签: cypressinput-field

解决方案


您需要的文档是How-do-I-get-an-input-s-value

// make an assertion on the value
cy.get('input').should('have.value', 'abc')

推荐阅读