Issue
I am trying to tell which of two radio buttons is checked. I have no problem testing the values of text inputs and dropdowns, but I just can't seem to figure out how to test whether or not a radio button is checked.
I am using the selenium test driver with yii (not yii2) in php. Does anybody know how to do this?
For example, how would I determine which of the following radio buttons is checked?
<input id="gender_0" value="M" type="radio" name="gender">
<input id="gender_1" value="F" type="radio" name="gender">
The way that I am trying to do it now is like this
$this->assertNotNull('#gender_'.($gender == 'M' ? 0 : 1).':checked');
$this->assertNull('#gender_'.($gender == 'M' ? 1 : 0).':checked');
The following works in a web browser's console, but I don't know how to do it in php with yii's Selenium web driver.
console.assert(document.querySelector('#gender_0:checked') != null);
Solution
This solved the problem for me:
$this->assertChecked('id=gender_'.($gender == 'M' ? 0 : 1));
$this->assertNotChecked('id=gender_'.($gender == 'M' ? 1 : 0));
I used assertChecked and assertNotChecked instead of assertNotNull and assertNull, changed the '#' to 'id=', and removed ':checked'.
Answered By - hutch90
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.