Selenide test fails to interact with Material`s checkbox

女生的网名这么多〃 提交于 2019-12-20 07:32:14

问题


Dear stackoverflowers.

We are using Selenide framework in our project to write automation tests for UI. We switched to Material-UI recently and faced with technical problems when it comes to simple checkbox. I am trying to select checkbox.

SelenideElement rememberMeCheckBox = $(By.cssSelector("input[type=\"checkbox\"]"));

rememberMeCheckBox.setSelected(isSelected);

But while doing that I get an exception:

Element should be visible {input[type="checkbox"]}
Element: '<input type="checkbox" value="on" displayed:false></input>'

And indeed when I check the real DOM it contains opacity: 0:

When I set the opacity by force my automation tests works well. How to deal with that ?


回答1:


It's not a Selenide problem, but a common Selenium problem. Selenium defines elements with "opacity: 0" as invisible. See How to force Selenium WebDriver to click on element which is not currently visible?

One simple way to enable this checkbox is to click its parent element:

$("input[type=\"checkbox\"]").parent().click();

At least it works for me.



来源:https://stackoverflow.com/questions/39349919/selenide-test-fails-to-interact-with-materials-checkbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!