被另一个元素 Cypress 覆盖

Yev*_*lov 6 javascript node.js cypress

重试超时:cy.select() 失败,因为此元素:

<select aria-describedby="searchDropdownDescription" class="nav-search-dropdown searchSelect" data-nav-digest="Xa0GQ+pPQ/tdsV+GmRWeXB8PUD0=" data-nav-selected="0" id="searchDropdownBox" name="url" style="display: block;" tabindex="0" title="Search in">...</select>
Run Code Online (Sandbox Code Playgroud)

被另一个元素覆盖:

<input type="text" id="twotabsearchtextbox" value="" name="field-keywords" autocomplete="off" placeholder="" class="nav-input" dir="auto" tabindex="0" aria-label="Search">
Run Code Online (Sandbox Code Playgroud)

修复此问题,或使用 {force: true} 禁用错误检查。我的代码:

describe('Amazon test', function()
{
    it('Matching book', function()
    {
        cy.visit("https://amazon.com")
        cy.title().should('eq',"Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more")
        cy.get('#twotabsearchtextbox').click({force: true}).get('#searchDropdownBox').select('Books')
        
    })
  })
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

小智 9

您想要单击该<select>标签。但赛普拉斯嘲笑一个真实的人。真人无法<select>在真实浏览器中单击 ,因为<select><input>.

所以我认为你可能需要首先调试你的页面代码。

提醒一下,部分覆盖也会触发这个问题。


A J*_*A J 7

尝试这个:

cy.get('#twotabsearchtextbox').click().get('#searchDropdownBox').select('Books',{force: true})
Run Code Online (Sandbox Code Playgroud)

  • 如果我不想使用“{force:true}”怎么办? (3认同)