Jump to content

Checkbox control?


Fox2
 Share

Recommended Posts

Should be easy, but having no success...

I've got a form with the following checkbox control definition:

<input name="myCheckbox" type="checkbox" value="1" id="myCheckbox" />

I'm trying to read it, and (in this example) set it to unchecked, then submit the form, but I'm having trouble with the checkbox.

I've got the form object $myForm and can manipulate text boxes on it and so on, it's just the checkbox that's stubborn. I can't see from HELP, what's missing.

$BrowserObjID = _IECreate("about:blank",0,1,1,-1) ; Create a temp window
...
_IENavigate($BrowserObjID, $myURL,0)
_IELoadWait($BrowserObjID)
$BrowserFormID = _IEFormGetObjByName($BrowserObjID, "myForm")
$CheckboxID = _IEFormElementGetObjByName($BrowserFormID, "myCheckbox")
$SavebuttonID = _IEFormElementGetObjByName($BrowserFormID, "mySavebutton")


then I've tried both:
_IEFormElementCheckBoxSelect($myForm,"myCheckbox","",0,"byValue",1)
and:
If _IEFormElementGetValue($CheckboxID)=1 then _IEAction($CheckboxID,"click")


_IEAction($SavebuttonID,"click")
_IELoadWait($BrowserObjID)
Edited by Fox2
Link to comment
Share on other sites

If you are going to select the checkbox "byvalue", and what you gave is value="1", then it would be:

_IEFormElementCheckBoxSelect($myForm,"1","",0,"byValue",1)

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

If you are going to select the checkbox "byvalue", and what you gave is value="1", then it would be:

_IEFormElementCheckBoxSelect($myForm,"1","",0,"byValue",1)

:)

I'm not sure that's the problem. The situation is, I'm automating a webpage I've loaded, where the checkbox is in an unknown state, and I want to clear it. So I don't know its present value, nor do I know if it's the only checkbox with that value. It may be one of several check boxes, some of which are set, some unset. I'm trying to get the checkbox that's got id+name="myCheckbox" (which uniquely identifies it) and read + set its value.

It should be easy, and should be trivial IE manipulation... what's missing in the above attempt?

Link to comment
Share on other sites

I'm not sure that's the problem. The situation is, I'm automating a webpage I've loaded, where the checkbox is in an unknown state, and I want to clear it. So I don't know its present value, nor do I know if it's the only checkbox with that value. It may be one of several check boxes, some of which are set, some unset. I'm trying to get the checkbox that's got id+name="myCheckbox" (which uniquely identifies it) and read + set its value.

It should be easy, and should be trivial IE manipulation... what's missing in the above attempt?

The function _IEFormElementCheckboxSelect() only identifies the checkbox one of two ways, byValue or byIndex. You specifically want to ignore both and specify a different way, so it's not trivial.

You need to get the collection and walk through it looking for your unique conditions:

#include <IE.au3>

; ...

$colInputs = _IETagNameGetCollection($myForm, "input")
$iInputCnt = @extended
If $iInputCnt Then
    $i = 0
    For $oInput In $colInputs
        If ($oInput.type = "checkbox") And ($oInput.id = "myCheckbox") And ($oInput.name = "myCheckbox") Then
            MsgBox(64, "Found", "Tag input type checkbox index " & $i & " is a match.")
            If $oInput.checked Then
                $oInput.checked = False
                If $f_fireEvent Then
                    $oInput.fireEvent("onchange")
                    $oInput.fireEvent("onclick")
                EndIf
            EndIf
            ExitLoop
        EndIf
        $i += 1
    Next
Else
    MsgBox(16, "Error", "No input tags found in form.")
EndIf

The "If $oInput.checked Then ... EndIf" section is lifted straight from Dale's IE.au3.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...