So I have this problem where I run a protractor/selenium test and sometimes a radio-button is already checked during the test and sometimes its not.
etc:
<div id="TRUCK" class="radio-item checked" data-gtm="truck">
or
<div id="TRUCK" class="radio-item" data-gtm="deliveryOpt-truck">
where you can see the class sometimes have the "checked" init and sometimes not.
What I am trying to do solve is that I want to make a function that clicks IF the radio-button is not checked and if its already checked then we just continue.
What I managed to do is:
it('Clicking Truck button', function (done) {
browser.driver
.then(() => browser.wait(EC.presenceOf(element(by.id("TRUCK")))), 30000, "Timed out button")
.then(() => browser.executeScript("arguments[0].click();",element(by.id("TRUCK")).getWebElement()))
.then(() => done());
however the problem is that it will uncheck it if the radio-button is already checked which is not good. So again.
I am trying to make a function that clicks. If the radio-button is not checked then we click. If its already checked then we continue.
How am I able to do that?