Forum Discussion

alexpat's avatar
alexpat
Occasional Contributor
15 years ago

How would I select these radiobuttons?

I have a couple of radiobuttons I want to select between but I can't seem to be able to find the right way to find them on the page to select them.





<div class="formtitle">Email Type:</div>


<div class="formfield">


<table id="ctl00_ContentPlaceHolder1_emailTypeRadioButton" border="0">


<tbody>


<tr>


<td>


<input id="ctl00_ContentPlaceHolder1_emailTypeRadioButton_0" name="ctl00$ContentPlaceHolder1$emailTypeRadioButton" value="False" checked="checked" type="radio">


<label for="ctl00_ContentPlaceHolder1_emailTypeRadioButton_0">HTML</label>


</td>


</tr>


<tr>


<td>


<input id="ctl00_ContentPlaceHolder1_emailTypeRadioButton_1" name="ctl00$ContentPlaceHolder1$emailTypeRadioButton" value="True" type="radio">


<label for="ctl00_ContentPlaceHolder1_emailTypeRadioButton_1">PlainText</label>


</td>


</tr>


</tbody>


</table>


</div>


</div>



  

This is my amateurish attempt at trying to select the radio button with the lable PlainText



set emailType = PageObj.NativeWebObject.Find("name", "ctl00$ContentPlaceHolder1$emailTypeRadioButton", "input")



call emailType.RadioButton.SetFocus("PlainText").Click

Anyone care to point/shove me in the correct direction?
  • Hi Alex,


    You can try using a script similar to the example we have created. Before running the script, replace "<PageObject>" in the fifth code line with the actual name of the page displayed in your browser.


      'VBScript


    Sub Main

      Dim PageObj, wTable, strText

      Set PageObj = <PageObject>

      set wTable = PageObj.NativeWebObject.Find("id", "ctl00_ContentPlaceHolder1_emailTypeRadioButton", "Table")

      strText = "PlainText"

      If checkItem(wTable, strText) Then

        Log.Message "The '" & strText & "' button is in the '" & wState(wTable, strText) & "' state."

      End If

    End Sub


    Function checkItem(wTable, strText)

      Dim wCellRButton, wRButton

      checkItem = False

      Set wCellRButton = wTable.FindChild("innerText", "*" & strText & "*")

      If Not wCellRButton.Exists Then

        Log.Error "Wrong button text."

        Exit Function

      End If

      Set wRButton = wCellRButton.RadioButton("*")

      wRButton.Click

      checkItem = True

    End Function


    Function wState(wTable, strText)

      Dim wCellRButton, wRButton 

      wState = False

      Set wCellRButton = wTable.FindChild("innerText", "*" & strText & "*")

      If Not wCellRButton.Exists Then

        Log.Error "Wrong button text."

        Exit Function

      End If

      Set wRButton = wCellRButton.RadioButton("*")

      wState = wRButton.checked

    End Function

  • alexpat's avatar
    alexpat
    Occasional Contributor
    Wow, so I was close with my attempt then :-)



    Thanks for the help. That's given me a lot of ideas on how to do some other things I was struggling with.