使用赛普拉斯从列表框中提取值

时间:2019-11-04 13:09:58

标签: javascript cypress

      <div class="MuiFormControl-root MuiTextField-root MuiFormControl-fullWidth" data-testid="timezone-input">
          <div class="MuiInputBase-root MuiInput-root MuiInputBase-fullWidth MuiInput-fullWidth MuiInputBase-formControl MuiInput-formControl">
             <div class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiInputBase-input MuiInput-input MuiInputBase-inputSelect" tabindex="0" role="button" aria-haspopup="listbox">Europe/London</div>
               <input type="hidden" value="Europe/London">
<svg class="MuiSvgIcon-root MuiSelect-icon" focusable="false" viewBox="0 0 24 24" aria-hidden="true" role="presentation"><path d="M7 10l5 5 5-5z"></path></svg></div></div>

如何使用cypress从列表框中提取值?我使用了以下代码

cy.get('[data-testid="timezone-input"] div div').invoke("val").should("eq", "Europe/London");

但是我得到CypressError: Timed out retrying: expected '' to equal 'Europe/London

1 个答案:

答案 0 :(得分:0)

不确定是否要检查divinput的内容,但是我会尝试其中之一。

对于div

cy.get('[data-testid="timezone-input"] div div').contains('Europe/London');

对于input

cy.get('[data-testid="timezone-input"] input').should('have.value', 'Europe/London');