Sign in to follow this  
Followers 0
NSearch

IE.au3 - Click Checkbox depending on value

6 posts in this topic

#1 ·  Posted (edited)

Is there a way to check a checkbox on a webpage, depending on its value?

<tr valign="top">
    <td><div class="modHeadPad"><input class="rad" name="Number002" type="checkbox" value="111111111111111"></div></td>
    <td colspan="2"><div class="modulepad">11111111111111</div></td>
    <td colspan="2"><div class="modulepad">31.00</div></td>
    <td colspan="1"><div class="modulepad">Blah</div></td>
</tr>
<tr>
    <td colspan="6"><img alt="" border="0" height="5" src="/images/1.gif" width="1"></td>
</tr>
<tr bgcolor="#ffffff">
    <td colspan="6"><img alt="" border="0" height="5" src="/images/1.gif" width="1"></td>
</tr>
<tr bgcolor="#ffffff" valign="top">
    <td><div class="modHeadPad"><input class="rad" name="Number003" type="checkbox" value="22222222222222"></div></td>
    <td colspan="2"><div class="modulepad">2222222222222222</div></td>
    <td colspan="2"><div class="modulepad">31.00</div></td>
    <td colspan="1"><div class="modulepad">blah</div></td>
</tr>
<tr bgcolor="#ffffff">
    <td colspan="6"><img alt="" border="0" height="5" src="/images/1.gif" width="1"></td>
</tr>
<tr>
    <td colspan="6"><img alt="" border="0" height="5" src="/images/1.gif" width="1"></td>
</tr>
<tr valign="top">
    <td><div class="modHeadPad"><input class="rad" name="Number004" type="checkbox" value="33333333333333"></div></td>
    <td colspan="2"><div class="modulepad">333333333333333</div></td>
    <td colspan="2"><div class="modulepad">31.00</div></td>
    <td colspan="1"><div class="modulepad">blah</div></td>
</tr>
Edited by NSearch

Share this post


Link to post
Share on other sites



Can you give us an example?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Something like this:

If $check_box_value = "111111111111111" then
   _IEFormElementSetValue($check_box)
EndIf
Edited by NSearch

Share this post


Link to post
Share on other sites

A little background on radio and checkboxes is needed I think.

There is both an individual checkbox (or radio button - I'll just refer to checkboxes from here on out) and there is a collection of them that act as a group (aka collection). All checkboxes with the same "name" form a collection. One way of accessing these objects is to use _IEFormElementGetObjByName() and use the zero-based index parameter to instantiate the individual checkboxes within the collection of checkboxes of the same name.

The important distinction with checkboxes is that the collection does not have a value -- only the individual checkboxes have a value -- these values can be read with _IEFormElementGetValue() and can be set with _IEFormElementSetValue().

These individual checkboxes also have a boolean property of .checked that you can either query or set. Only checkboxes that are checked will post their name-value pairs when the form is submitted.

If your goal is to specify which of the existing value(s) associated with the checkboxes is posted by the form, you must set the checked attribute od the associated checkbox to True. For example:

$oForm = _IEFormGetObjByName($oIE, "aForm")
$oCheckbox = _IEFormElementGetObjByName($oFrom, "Number001", 2); 3rd checkbox
$oCheckbox.checked = True

Make sense?

Dale

Note: If you are actually trying to change the value assiciated with a particular checkbox, then you would use _IEFormElementSetValue()


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This works for me.

Thanks Dale.

While 1
            $i = $i + 1
            $form_objects = _IEFormGetObjByIndex($oIE, 2)
        
            $o_number = _IEFormElementGetObjByName($form_objects, "Number00"&$i)
            $blah = _IEFormElementGetValue($o_number)
            If $blah = $yuck Then
                $ocheck_box = _IEFormElementGetObjByName($form_objects, "Number00"&$i, 0)
                $ocheck_box.checked = True
                ExitLoop
            EndIf
        WEnd
Edited by NSearch

Share this post


Link to post
Share on other sites

Is there a option in _IEFormElementGetObjByName to select "bytext"

Like this

_IEFormElementCheckBoxSelect($oForm, "run", "checkboxG2Example", 1, "bytext")

Thanks & Regards

Sathish V.

Share this post


Link to post
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
Sign in to follow this  
Followers 0