(Robotium) How to select a RadioButton in a RadioGroup

android, android-intent, android-layout, robotium

Solution

Try below code

RadioButton rb = (RadioButton) solo.getView(R.id.yes_btn);
solo.clickOnView(rb);

solo.clickOnRadioButton() takes view index as argument, while you are passing Resource ID.

Problem

In my Android app view layout, I have a `<RadioGroup>` which contains two `<RadioButton>`: ``` <RadioGroup android:id="@+id/my_radio_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:id="@+id/yes_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/yes" /> <RadioButton android:id="@+id/no_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no" /> </RadioGroup> ``` I use Robotium library to write a JUnit test for this radio group to selection one Radio Button. The test code snippet is: ``` Solo solo = new Solo(getInstrumentation(), getActivity()); ... solo.clickOnRadioButton(R.id.yes_btn); //I expect the "yes" radio button will be selected ``` I expected the above test code would select the "YES" Radio button, But when run it, it raise an error: ``` junit.framework.AssertionFailedError: 2131427675 RadioButtons are not found! at com.jayway.android.robotium.solo.Waiter.waitForAndGetView(Waiter.java:417) at com.jayway.android.robotium.solo.Clicker.clickOn(Clicker.java:374) at com.jayway.android.robotium.solo.Solo.clickOnRadioButton(Solo.java:1063) ... ``` How can I select one `<RadioButton>` in a `<RadioGroup>` then with Robotium??

Original source