0

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:

enter image description here

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

enter image description here

AlexeiBerkov
  • 427
  • 1
  • 6
  • 16

1 Answers1

4

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.

Community
  • 1
  • 1
Andrei Solntsev
  • 480
  • 2
  • 8
  • It worked for me too. But I am wondering how to pick specific checkbox among a few ones. What attribute shall we use apart from type? – fiskra Jun 20 '18 at 12:11
  • Nobody can answer but you. It depends on your application. You need to find some locator or at least xpath. – Andrei Solntsev Jun 26 '18 at 17:06