[英]How to get an element value that is not showing in html code with Cypress?
這是我的元素的代碼
<input type="text" class="nameOfClass" id="someid" name="somename" maxlength="255" placeholder="justholder" ng-model="model" tooltip-placement="top" tooltip-trigger="mouseenter" tooltip-animation="false" style="">
如您所見,沒有屬性值,但我可以清楚地看到我正在嘗試自動化的 web 應用程序的該文本字段中有文本。
所以我的問題是,我不知道如何獲取文本字段的值。 我試過谷歌瀏覽器檢查器來查找價值在哪里,但沒有任何運氣。 在我讀到的某處,緩存可能會導致此問題,但在網絡控制台中,我可以看到請求響應中的值。
謝謝
假設您想獲取寫入文本字段中的值,您可以通過調用val
來獲取它。
cy.get('#someid')
.invoke('val')
.then((value) => {
cy.log(value) //logs the value
})
如果要對值應用任何斷言,可以:
cy.get('#someid').should('have.value', 'your-value')
如果您指的是type="text"
,那不是用戶輸入的文本 - 它是一個屬性,告訴輸入允許哪些值。
你也可以有type="number"
, type="date"
, type="color"
等
檢查輸入是否為“文本”類型將通過此完成,
cy.get('input#someid').should('have.attr', 'type', 'text')
檢查 value 屬性將像這樣完成
cy.get('input#someid')
.type('entering a value') // there's nothing in value yet
.should('have.value', 'entering a value')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.