无论如何,柏树禁用的按钮无论如何都单击而无需等待
这不是我期望柏树的行为: 我有一个仅在下表中选中复选框的按钮。 在检查2行之前,请按下按钮:
button[data-e2e-button][disabled=true]
现在,柏树检查2行,并启用了按钮。即“ [disabled = true]”消失。我的代码看起来像这样:
非工作代码:
cy.contains(`[data-e2e-button]`, buttonLabel, BUTTON_OPTS).should('not.be.disabled').should('be.visible').click...
单击此元素时,似乎没有等到启用按钮。
只有当我单独等待残疾人= the true以消失时,它起作用了:
工作代码:
cy.contains('[data-e2e-button][aria-disabled="true"]', buttonLabel, BUTTON_OPTS).should('not.exist');
cy.contains(`[data-e2e-button]`, buttonLabel, BUTTON_OPTS).should('not.be.disabled').should('be.visible').click...
这对我来说似乎很丑陋,因为它可以确保两次残疾消失。
这是HTML代码: 启用:
<span role="tooltip">
<a class="MuiMenuItem-root MuiMenuItem-dense MuiMenuItem-gutters MuiButtonBase-root css-brjsa3" tabindex="-1" role="menuitem"><span>
<span class="MuiBox-root css-1jjwf1f">Two Checkbox button</span>
</span>
<span class="MuiTouchRipple-root css-w0pj6f"></span>
</a>
</span>
禁用
<span role="tooltip">
<a class="MuiMenuItem-root MuiMenuItem-dense Mui-disabled MuiMenuItem-gutters MuiButtonBase-root Mui-disabled css-brjsa3" tabindex="-1" aria-disabled="true" role="menuitem"><span>
<span class="MuiBox-root css-1jjwf1f">Two Checkbox button</span>
</span></a></span>
This is not how I would expect cypress to behave:
I have a button which is only enabled when to checkboxes are checked in the table below.
Before the checking of the 2 rows, the button is greyed out with:
button[data-e2e-button][disabled=true]
Now cypress checks the 2 rows and the button becomes enabled. i.e. the "[disabled=true]" disappears. My code looks like this:
Non Working Code:
cy.contains(`[data-e2e-button]`, buttonLabel, BUTTON_OPTS).should('not.be.disabled').should('be.visible').click...
When it clicks on this element, it seems like it did not wait until the button is enabled.
Only if I have a separate wait for the disabled=true to disappear it works:
Working Code:
cy.contains('[data-e2e-button][aria-disabled="true"]', buttonLabel, BUTTON_OPTS).should('not.exist');
cy.contains(`[data-e2e-button]`, buttonLabel, BUTTON_OPTS).should('not.be.disabled').should('be.visible').click...
This seems kind of ugly to me, as it ensures twice for disabled to disappear.
Here is the html code:
ENABLED:
<span role="tooltip">
<a class="MuiMenuItem-root MuiMenuItem-dense MuiMenuItem-gutters MuiButtonBase-root css-brjsa3" tabindex="-1" role="menuitem"><span>
<span class="MuiBox-root css-1jjwf1f">Two Checkbox button</span>
</span>
<span class="MuiTouchRipple-root css-w0pj6f"></span>
</a>
</span>
DISABLED
<span role="tooltip">
<a class="MuiMenuItem-root MuiMenuItem-dense Mui-disabled MuiMenuItem-gutters MuiButtonBase-root Mui-disabled css-brjsa3" tabindex="-1" aria-disabled="true" role="menuitem"><span>
<span class="MuiBox-root css-1jjwf1f">Two Checkbox button</span>
</span></a></span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的属性为
aria-disabled =“ true”
如下所示,则
。禁用')
不使用该属性。他们只能使用属性
disabled =“ true”
,似乎没有存在。它解释了为什么它起作用
,因为在第一行中确实检查了该属性。
尝试其中一个
或
If your attribute is
aria-disabled="true"
as shown herethen
.should('be.disabled')
and.should('not.be.disabled')
do not work with that attribute.They would only work with attribute
disabled="true"
which does not seem to be present.It explains why this works
because in the first line does check that attribute.
Try either of these
or
在使用负面断言时要小心,它们通常不太可靠。而不是使用
。
Be careful when using negative assertions, they are often less reliable. Instead of using
.should('not.be.disabled')
before clicking the element, make sure the element is disabled before meeting the enabled condition.您可以做这样的事情。您也可以提出其他选择器,如果这不起作用,这个想法仍然相同。
如果
cy.get()
不起作用,则可以与选择器和按钮标签一起使用,例如:You can do something like this. You can come up with a different selector as well, if this doesn't work, the idea remains the same.
In case
cy.get()
doesn't work, you can use contains with selector and button label, something like: