gpt4 book ai didi

select - 选定选项上的 Cypress IF-ELSE

转载 作者:行者123 更新时间:2023-12-03 07:50:11 24 4
gpt4 key购买 nike

我想检查是否在字段 1 中选择了“法国”选项,然后我在字段 2 中选择了“欧元”选项。

如果在字段 1 中选择“美国”选项,则在字段 2 中选择“美元”选项。

enter image description here

cy.get('State').then(($btn) => {
// assert on the text
if ($btn.text().to.equal('France')) {
cy.get('#vs3__combobox > .vs__actions').click() //Expands
cy.get('#dialog-2').contains('Euro').click() //Selects
} else {
cy.get('#vs3__combobox > .vs__actions').click() //Expands
cy.get('#dialog-2').contains('Dollars').click() //Selects
}
})

但我无法正确理解,而且我是 Cypress/Javascript 的新手。

谢谢

最佳答案

我的做法要简单得多,使用 invoke('val')获取 State <select> 的当前值元素。

根据value="FR",它要么是“FR”,要么是“US”,或者什么都不是。选项的属性。

cy.get('select#State')
.invoke('val') // what is selected
.then(selected => {
if (selected === 'FR') {
// do French stuff
}
if (selected === 'FR') {
// do USA stuff
}
if (selected === '') {
// default selected is the first option
cy.log('Nothing is selected')
}
})

获取text() <select>的不会告诉您当前选择的值是什么。

引用:Cypress examples (v13.3.3) - Selected value

关于select - 选定选项上的 Cypress IF-ELSE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77375814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com