Reputation: 31
I'd like to check if a radio button is selected or not with its id for instance.
Element that needs to be checked:
<input id="Evidence_of_Obstruction" class="" type="Radio" checked="" onclick="changeSaveStatus(this, "72");" value="0" name="Patency">
Upvotes: 3
Views: 11454
Reputation: 416
You can do something like...
if | !selenium.isChecked("Patency")
waitForElementPresent | name=Patency
click | name=Patency
waitForValue | name=Patency | on
endIf
The code above will check to see if the box is checked. If not, then it will check the box and verify that the action occurred as expected. The only downfall to the method above is I haven't found a way to do this with a check box using anything except NAME or ID. This should work if you used the name of the check box, which in your case is I haven't gotten this to work using XPATH or CSS, which would help in the even that the box doesn't show a change in status [xpath] when you check/uncheck it.
In the case that your check box either doesn't have any change in code on the webpage or for some reason you can't use either ID or NAME, then you'll do something like this:
storeValue | xpath=//input[@id="Evidence_of_Obstruction"][@name="Patency"] | isBoxChecked
if | storedVars['isBoxChecked']=='on'
goto | NEXT_TASK
else
waitForElementPresent | xpath=//input[@id="Evidence_of_Obstruction"][@name="Patency"]
click | xpath=//input[@id="Evidence_of_Obstruction"][@name="Patency"]
waitForValue | xpath=//input[@id="Evidence_of_Obstruction"][@name="Patency"] | on
endIf
label | NEXT_TASK
This code takes advantage of Selenium IDE identifying check boxes as unchecked (off) or checked (on). You can store the state of a check box and determine what to do with the check box, if anything, based on it's current state. Hopes this helps you or someone else who comes across this issue.
Upvotes: 0
Reputation: 3
Please use this below code:-
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
if( exists = driver.findElements( By.id("your id") ).size() != 0)
{
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
}
You can use rhis part of the code.
Upvotes: 0
Reputation: 73
Using Selenium IDE I prefer element ids, which would be close to what t3hn00b suggested:
Command: assertValue Target: id=Evidence_of_Obstruction Value: on
Upvotes: 1
Reputation: 11751
This is just:
<tr>
<td>verifyChecked</td>
<td>Evidence_of_Obstruction</td>
<td></td>
</tr>
Upvotes: 0
Reputation: 2028
In WebDriver this would be something like:
IWebElement element = _driver.FindElement(By.Id("Evidence_of_Obstruction"));
if(element.Selected)
; //then it is selected
else
; //then it is NOT selected
Alternatively, as t3hn00b eluded to, you could check another attribute such as Value or Checked. This can be done like so:
IWebElement element = _driver.FindElement(By.Id("Evidence_of_Obstruction"));
string result = element.GetAttribute("checked"); // or replace checked with value
//then check the strings contence.
Upvotes: 0
Reputation: 912
Command: assertValue Target: name='Patency' Value: on
or something quite similar to that. You can use the proposed commands in the Selenium IDE by right clicking on the radio button and chosing one of the commands.
Upvotes: 1