reactjs - 赛普拉斯获取兄弟姐妹输入并更改值?
问题描述
我是赛普拉斯的新手,我想获取输入字段来修改值。
我可以选择行然后是兄弟姐妹,但我不知道如何选择<input ....
. 在下图中,我们可以看到siblings
选择行元素,现在我想选择输入元素,但我做不到:
<td>
<input
className="form-control"
name="labelPred1"
type="text"
value={this.state.jsondata.prediction[k]}
onChange={e => this.onPred1Change(k, e.target.value)}
/>
</td>
it('modify prediction', () => {
cy.get('table').contains('td', 'jour son facebook')
.siblings()
.contains('input[name=labelPred1] ','0')
.type('2')
})
在上面的代码中,您可以看到我输入的 HTML 结构,然后是我的赛普拉斯测试,我也尝试contains(...)
将.get('input')
解决方案
Siblings 需要一个选择器,因此您可以将输入选择器移入其中,
cy.get('table')
.contains('td', 'jour son facebook')
.siblings('td input[name=labelPred1]') // specify td + child input
.type('2')
或者下一个 td
cy.get('table')
.contains('td', 'jour son facebook')
.next()
.find('input[name=labelPred1]') // within the next td
.type('2')
这.contains('input[name=labelPred1]','0')
不起作用,因为元素是 aninput
并且'0'
不在 text 属性上,它在 value 属性上。
.contains()
只查找标签之间的文本
这可能有效
cy.get('table')
.contains('td', 'jour son facebook')
.siblings()
.find('input[name="labelPred1"][value="0"]')
.type('2')
推荐阅读
- firebase - Web App 密钥限制不适用于 Firebase
- javascript - TypeScript 承诺会引发编译时错误,但不会引发运行时错误
- javascript - 如何在 V8 中检测从一种形状到另一种形状的过渡?
- python - 如何使用 tf.data 在 CNN 中包含 rgb 和灰度图像?
- javascript - Angular/JS 不保持对象顺序
- html - 我需要更改我的 html 文件中的颜色
- sql - 查看选择中的所有行是否符合条件
- excel - 格式化整个 Excel 工作簿宏中的单元格编号
- ios - IOS自定义进度条与CAShapeLayer
- python - 用正则表达式的dict值列表中的键替换字符串