PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] yii selenium radio button is checked?

 February 10, 2022     php, selenium-webdriver, yii     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing