Junit 基于单选按钮执行方法

Junit 基于单选按钮执行方法,junit,selenium-webdriver,junit4,Junit,Selenium Webdriver,Junit4,我有两个带有两个不同id的单选按钮radio1 id=“choice1” radio2 id=“choice2” 我想在检查radio1时运行一些方法。当radio2被选中时,运行其他程序 但它不起作用,因为我在布尔条件下使用void方法。但坦率地说,我不知道如何做,否则。 下面是我不工作的代码 私人机构{ } 错误:类型不匹配:无法从void转换为boolean 谢谢你的帮助 您可以尝试使用isChecked()或isSelected(),也可以实现onCheckedChangeListene

我有两个带有两个不同id的单选按钮radio1 id=“choice1” radio2 id=“choice2”

我想在检查radio1时运行一些方法。当radio2被选中时,运行其他程序 但它不起作用,因为我在布尔条件下使用void方法。但坦率地说,我不知道如何做,否则。 下面是我不工作的代码

私人机构{

}

错误:类型不匹配:无法从void转换为boolean


谢谢你的帮助

您可以尝试使用
isChecked()
或isSelected(),也可以实现onCheckedChangeListener

radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

                //handle the boolean flag here. 
                  if(arg1==true)
                         //Do something

                else 
                    //do something else

            }
        }); 
click()
不返回任何状态或布尔值,但执行单击。如果要检查单选按钮是否选中,请调用
.isSelected()

if(this.driver.findElement(By.id(“choice1”)).isSelected()){
验证选择(“idSelect”);
验证文件(“idDuree”);
}
if(this.driver.findElement(By.id(“choice2”)).isSelected()){
verifyDatePicker(“idDate”);
验证时间选择器(“idTime”);
}

当我尝试检查时,它不起作用,我不知道为什么!!错误:类型WebElement的方法isChecked()未定义,但当我尝试isSelected时,它工作正常(即使是选中的按钮而不是选中的按钮),谢谢您的回答!如果我能帮助你,我很高兴。在这种情况下,您可能希望接受此答案,甚至对其进行投票;-)
radioButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {

                //handle the boolean flag here. 
                  if(arg1==true)
                         //Do something

                else 
                    //do something else

            }
        });