In my testing framework, I have implemented a keyword-based approach using Selenium 3.x and Java. One of the web elements I am working with is:
<input id="radiobutton" name="webserviceBarFlg" onclick="setReadOnly(this)" class="foo-input-radio-margin foo-input-radio" type="radio" value="true" checked="checked">
<input id="radiobutton" name="webserviceBarFlg" onclick="setReadOnly(this)" class="foo-input-radio-margin foo-input-radio" type="radio" value="false" checked="checked">
There is a JavaScript method that affects other input elements.
function setReadOnly(obj) {
var varRadio = $(obj).val();
var input = $(obj).closest("tr").next("tr").find("input");
if(varRadio == "false") {
$(input).attr("readOnly", true);
} else {
$(input).attr("readOnly", false);
}
}
I have experimented with two solutions on Internet Explorer 11, Windows 10 Pro:
Solution 1
webElement.click();
Solution 2
private RemoteWebDriver remoteWebDriver;
//...
JavascriptExecutor executor = (JavascriptExecutor) remoteWebDriver;
executor.executeScript("arguments[0].click();", webElement);
However, I am still unable to trigger the onclick event. Any suggestions on how to achieve this?