我想在我的自动化测试中单击单选按钮。即使单选按钮在页面上可见,未选中的也有displayed:false属性。displayed:false如果 html 对象具有属性,Selenide 无法单击。错误是:Element should be visible {By.id: radio_btn_id}
这是我的单选按钮:
<input class="radio_class" id="radio_btn_id" name="radio_btn_name" type="radio" value="12" displayed:false></input>
我为删除该属性所做的尝试,但没有一个有效
SelenideElement element = $(By.id(id));
Selenide.executeJavaScript("document.getElementById('radio_btn_id').removeAttribute('displayed:false')", element);
Selenide.executeJavaScript("document.getElementById('radio_btn_id').removeAttribute(\"displayed:false\")", element);
Selenide.executeJavaScript("jQuery('select:not(:visible)').css('display','block')", element);
我试图删除selected:true财产并且它起作用了。我不知道为什么它不起作用displayed:false。你们有什么想法吗?
[编辑] 接受的答案是Selenium版本。它Selenide更加干净和简单:
SelenideElement element = $(By.id(id));
Selenide.executeJavaScript("document.getElementById('"+ id+ "').click();", element);
[解决方案]