Jump to content

Can't check a checkbox twice


buymeapc
 Share

Recommended Posts

Hi all,

I'm trying to check a checkbox on a webpage using _IEFormElementCheckBoxSelect() or even _IEAction(), but after I use either of these functions once, the script errors out. It's like I have one chance to either query or check this checkbox and that's it. Like the object gets lost after one use. The errors I get are these:

--> IE.au3 V2.4-0 Error from function _IEFormElementCheckboxSelect, $_IEStatus_InvalidObjectType
C:\Program Files\AutoIt3\Include\IE.au3 (2418) : ==> The requested action with this object has failed.:
$o_object.Click()
$o_object.Click()^ ERROR

$oForm =    _IEFormGetObjByName($oIE, "Form1")
$oSelect =  _IEGetObjByName($oIE, "TabSystemOptions:ListBoxChoices1")
_IEFormElementOptionselect($oSelect, "HSS", 1, "byText", 1)
$oSelect =  _IEGetObjByName($oIE, "TabSystemOptions:ListBoxChoices2")
_IEFormElementOptionselect($oSelect, "HSS", 1, "byText", 1)
$oACE =     _IEGetObjByName($oIE, "TabSystemOptions:CheckboxApplyACEOutpat")
;_IEFormElementCheckBoxSelect($oForm, 0, "TabSystemOptions:CheckboxApplyACEOutpat", 0, "byIndex", 1)
$status = _IEFormElementCheckBoxSelect($oForm, 0, "TabSystemOptions:CheckboxApplyACEOutpat", -1, "byIndex", 1)
;_IEAction($oACE, "click")
MsgBox(0, "Before", $status)
$status = _IEFormElementCheckBoxSelect($oForm, 0, "TabSystemOptions:CheckboxApplyACEOutpat", -1, "byIndex", 1)
;_IEAction($oACE, "click")
MsgBox(0, "Here's the error", $status)

The one thing that might be tripping me up is that I'm doing this without seeing the values get selected or modified since there is a "tabbed javascript page" where I have to click a tab to see the values I'm working with and I can't seem to click the tab using AutoIT.

Link to comment
Share on other sites

Unfortunately, I cannot post the URL in question which kind of hinders any possibility of someone testing the website, I know. ;) It's on a local testing server at my place of work. So, I had to replace the IP with the localhost IP.

$oIE = _IECreate("http://127.0.0.1/hss/authadmin/authadmin.aspx")

Is _IEFormElementCheckBoxSelect() failing because I'm not on the javascript-created tab with the control literally visible?

Link to comment
Share on other sites

Found the issue. It seems that once an item inside a listbox control on the website was selected, the page would refresh. Since I was only calling the form object once, after the refresh, the object was lost. So, I just re-call the form after an _IELoadWait() and everything worked fine.

Here's my code in case someone has a similar issue.

$oIE = _IEAttach("Authentication")

AceCheck(True)

Func AceCheck($val = False)
    $oForm =    _IEFormGetObjByName($oIE, "Form1")
    $oSelect =  _IEGetObjByName($oIE, "TabSystemOptions:ListBoxChoices1")
    _IEFormElementOptionselect($oSelect, "HSS", 1, "byText", 1)
    _IELoadWait($oIE, 10);Wait for the page to load
    $oForm =    _IEFormGetObjByName($oIE, "Form1");get the form object again since the page has refreshed
    $oSelect =  _IEGetObjByName($oIE, "TabSystemOptions:ListBoxChoices2")
    _IEFormElementOptionselect($oSelect, "HSS", 1, "byText", 1)
    $oACE =     _IEGetObjByName($oIE, "TabSystemOptions:CheckboxApplyACEOutpat")

    If $val = True Then _IEFormElementCheckBoxSelect($oForm, 0, "TabSystemOptions:CheckboxApplyACEOutpat", 1, "byIndex", 1)
    If $val = False Then _IEFormElementCheckBoxSelect($oForm, 0, "TabSystemOptions:CheckboxApplyACEOutpat", 0, "byIndex", 1)
EndFunc
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...