Button is covered by another element.

huangapple go评论54阅读模式
英文:

Button is covered by another element

问题

以下是翻译好的部分:

"我需要一些帮助。我有一个测试,需要登录一个网站并选择一个状态。当我点击更新按钮时,模态框关闭,另一个模态框弹出,显示更新成功消息,有一个确定按钮和一个关闭按钮。

我需要验证模态框上的消息以及确定按钮是否可用,但由于以下错误,无法执行操作:

超时后重试,等待4000毫秒:预期'<button.btn.btn-success>'应可见。

这个元素'<button.btn.btn-success>'不可见,因为它具有CSS属性:position: fixed,被另一个元素遮挡:

这是我使用的代码:

cy.get('.modal-body > :nth-child(3) > .col-sm-9 > .form-control').type('No Good Reason')
cy.get('.modal-body > :nth-child(4) > .col-sm-9 > .form-control').type('Testing Memo')
cy.get('.btn-primary > .ng-scope').click()
//检查更新成功模态框是否正确显示
cy.get('#updateSuccess').find(".modal-title").contains('Update OK').should('exist')
cy.get('.modal-body').contains('Financial Account Status Change (General) was updated OK').should('exist')

这是我遇到问题的元素和点击操作:

cy.get('#updateSuccess').find('.btn').contains('OK').should('exist').click()

这是DOM。

感谢您提前的帮助。

更新:好的,我已经能够使用'exist'检查模态框上的元素,所以我进展了一点。但我仍然无法点击"确定"按钮,因为该按钮被前一个模态框上的元素遮挡。"

请注意,我只提供了代码和错误信息的翻译,不包括回答翻译问题的请求。如果需要更多帮助,请提出具体问题。

英文:

I need some help please.

I have a test where i log into a website and select a status. When i click on the update button the modal closes and another modal opens with a update success message and an ok button and an x button.

I need to validate what the message on the modal says and that the ok button works, but its not letting because of this error

Timed out retrying after 4000ms: expected '<button.btn.btn-success>' to be 'visible'

This element <button.btn.btn-success> is not visible because it has CSS property: position: fixed and it's being covered by another element:

<textarea ng-disabled="loading" class="form-control ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" ng-model="memo" name="memo" placeholder="" required="" style="" disabled="disabled"></textarea>

This is my code im using to

cy.get(&#39;.modal-body &gt; :nth-child(3) &gt; .col-sm-9 &gt; .form- 
control&#39;).type(&#39;No Good Reason&#39;)
cy.get(&#39;.modal-body &gt; :nth-child(4) &gt; .col-sm-9 &gt; .form- 
control&#39;).type(&#39;Testing Memo&#39;)
cy.get(&#39;.btn-primary &gt; .ng-scope&#39;).click()
//check the update ok modal appears correctly
cy.get(&#39;#updateSuccess&#39;).find(&quot;.modal- 
title&quot;).contains(&#39;Update OK&#39;).should(&#39;exist&#39;)
cy.get(&#39;.modal-body&#39;).contains(&#39;Financial Account Status 
Change (General) was updated OK&#39;).should(&#39;exist&#39;)

This is the element and click action im having problems with
cy.get('#updateSuccess').find('.btn').contains('OK').should('exist').click()

This is the DOM

Button is covered by another element.

Thanks in advance for your help

UPDATE: OK i was able to check the elements on the modal using the exist, so I got a bit further. I still cant click on the ok button as the button is covered by an element on a previous modal

答案1

得分: 5

如果您确信用户可以访问按钮,请在点击时添加{force:true}选项。

Cypress会检查可操作性,但有时可能会出错。

在这种情况下,force选项是一个后门,允许您在不检查可操作性的情况下继续测试。

cy.get('.modal-body > :nth-child(3) > .col-sm-9 > .form-control').type('无明显原因')
cy.get('.modal-body > :nth-child(4) > .col-sm-9 > .form-control').type('测试备忘录')

cy.get('.btn-primary > .ng-scope').click({force:true})  

cy.get('#updateSuccess').find('.btn').should('be.visible')
cy.get('#updateSuccess').find('.btn').click()
英文:

If you are sure that the user can access the button, then add the {force:true} option to the click.

Cypress checks for actionability but sometimes gets it wrong.

In such a case the force option is a back-door that allows you to continue the test without checking for actionability.

cy.get(&#39;.modal-body &gt; :nth-child(3) &gt; .col-sm-9 &gt; .form-control&#39;).type(&#39;No Good Reason&#39;)
cy.get(&#39;.modal-body &gt; :nth-child(4) &gt; .col-sm-9 &gt; .form-control&#39;).type(&#39;Testing Memo&#39;)

cy.get(&#39;.btn-primary &gt; .ng-scope&#39;).click({force:true})  
  
cy.get(&#39;#updateSuccess&#39;).find(&#39;.btn&#39;).should(&#39;be.visible&#39;)
cy.get(&#39;#updateSuccess&#39;).find(&#39;.btn&#39;).click()

huangapple
  • 本文由 发表于 2023年4月13日 16:33:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003333.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定