我正試圖全力以赴values以select tag擁有一個陣列。這是我的代碼:
cy.get('[data-tab-name-prefix="selectedFonds[0]]')
.scrollIntoView()
.should('be.visible')
.find('[name="selectedFonds[0][name]"]')
.find('option')
.invoke('attr', 'value').then($options => {
cy.log($options)
})
<div data-tab-name-prefix="selectedFonds[0]">
<div class= something>
<div class= something else>
<select class=form-control name="selectedFonds[0][name]">
<option value="first value"> First Value </option>
<option value="second value"> Second Value </option>
<option value="third value"> Third Value </option>
<option value="forth value"> Forth Value </option>
</select>
</div>
</div>
</div>
問題是它只回傳第一個選項......不是全部。
uj5u.com熱心網友回復:
我的建議是使用 data 屬性定位元素,然后執行within(). 然后以選擇元素為目標并執行children(). 后跟一個each()塊來迭代每個選項元素。
const values = ['first value', 'second value', 'third value', 'fourth value']
cy.get('[data-tab-name-prefix="selectedFonds[0]]')
.scrollIntoView()
.should('be.visible')
.within( ($el) => {
cy.get('select')//based on your HTML you have only one select inside this div
.should('be.visible')
.children()
.each( ($el, index) => {
cy.get($el)
.should('have.value', values[index])
})
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/496591.html
標籤:javascript jQuery 数组 自动化测试 柏
上一篇:從Html.BeginFormASP.NETMVC呼叫兩個動作
下一篇:倒數計時器每15分鐘一小時
