swh2u Posted June 29, 2016 Share Posted June 29, 2016 Problem: the unique value of my check box that needs to be updated is listed in the "Label" section of my Checkbox values. I need to check the value based on the label. I've been unsuccessful getting the value out to be able to update it. (see screen shot) any ideas on how best to extract the data based on the "Label" realizing that next time I enter the system I may have entered a value that is now loaded into this same input name of ctl100$maincontent$cleintsiteslist$235? Link to comment Share on other sites More sharing options...
swh2u Posted June 29, 2016 Author Share Posted June 29, 2016 Thoughts, I'll need to iterate through each of the values in the check box and store the Name or ID of each of the values and their corresponding Label. Then look through labels to determine which name or id I need then send an update to add the check box and continue. I'm hoping that this is not the best option. But its what I've come up with so far. No code written yet. But will share once I have it unless someone knows of a better way. Link to comment Share on other sites More sharing options...
MichaelHB Posted June 29, 2016 Share Posted June 29, 2016 Hi @swh2u One question first, are the labels always bound to the same ID? For example: "Total Care Members" have always the ID "ct100........_235"? If not for some reason or the ID is not static, i do not suggest you to loop through every element. Grab the document HTML (_IEDocReadHTML) and then use string functions (regex is a good call here) to build an array[ID][LABEL] with the element ID and its respective Label and then filter the results that you want. It will be easier to grab the element by ID to later check/uncheck it. Link to comment Share on other sites More sharing options...
swh2u Posted June 29, 2016 Author Share Posted June 29, 2016 Hi @MichaelHB, No the data changes when another element is added. not the same each time but loaded into the ID. Steve Link to comment Share on other sites More sharing options...
MichaelHB Posted June 29, 2016 Share Posted June 29, 2016 (edited) Ok, so i suggest you do like i said in #3, use _IEDocReadHTML and string functions to get every ID and its respective Label (like array[ID][LABEL]). This way it will be faster than loop through every element. Then all you need is to match the Label to the ones you want and grab the element by its ID. Edited June 29, 2016 by MichaelHB spell Link to comment Share on other sites More sharing options...
swh2u Posted June 30, 2016 Author Share Posted June 30, 2016 (edited) Here's what I ended up doing: Global $SPS = "Documents Members" Func checkbox () Local $sHTML = _IEDocReadHTML($oIE) ;get position of my string $position = StringInStr($sHTML, $SPS) ;Trim Left to exclude all variables before the "matched" variable I need. $position = ($position - 192) MsgBox($MB_SYSTEMMODAL, "Document Source", $position) $sHTML = StringTrimLeft ( $sHTML, $position) $InputNameStart = StringInStr($sHTML, "input name=") $InputNameStart = ($InputNameStart + 11) $sHTML = StringTrimLeft ( $sHTML, $InputNameStart) $InputNameEnd = StringInStr($sHTML, "id=") $InputNameEnd = ($InputNameEnd - 3) $trim = StringLen($sHTML) $trim = ($trim - $InputNameEnd) $sHTML = StringTrimRight ( $sHTML, $trim) ;$sHTML now has the name of the check box I'll need to update. MsgBox($MB_SYSTEMMODAL, "Check Box Variable Name to update:","The value you'll want to check is" & $sHTML) EndFunc Thanks for the suggestions! Edited June 30, 2016 by swh2u Link to comment Share on other sites More sharing options...
MichaelHB Posted June 30, 2016 Share Posted June 30, 2016 Glad that you make it work. Remember to post your codes in tags (there is a symbol like this one < > when posting or editing). Also take a look at the stringregex function. Link to comment Share on other sites More sharing options...
swh2u Posted June 30, 2016 Author Share Posted June 30, 2016 (edited) Updated, Thanks! Next question. I need to update the check box now that I know the value of the check box. But when I use: ;Attmept 1 Local $oForm = _IEFormGetObjByName($oIE, "ctl00$MainContent$ClientSitesList$236") _IEFormElementSetValue($oForm, "ctl00$MainContent$ClientSitesList$236") attempt 1 returns --> IE.au3 T3.0-2 Warning from function _IEFormGetObjByName, $_IESTATUS_NoMatch --> IE.au3 T3.0-2 Error from function _IEFormElementSetValue, $_IESTATUS_InvalidObjectType Edited June 30, 2016 by swh2u Link to comment Share on other sites More sharing options...
MichaelHB Posted June 30, 2016 Share Posted June 30, 2016 (edited) First you have to notice that you are not grabbing the form object. Remember the common order: oIE = IE object. oForm = Form element inside the oIE. oObjectInTheForm = Object (many types) inside the Form element. You will just check the box or its possible that you will need to uncheck it? First case: ;Attmept 2 Local $oObject = _IEGetObjByName($oIE, "ctl00$MainContent$ClientSitesList$236") _IEAction($oObject, "click") Second case: ;Attmept 3 Local $oObject = _IEGetObjByName($oIE, "ctl00$MainContent$ClientSitesList$236") $oObject.checked = False ; Uncheck the element $oObject.checked = True ; Check the element In the second case you can use the function "_IEFormElementCheckBoxSelect" but you will need a few more line codes, there is an example in the helpfile. Edited June 30, 2016 by MichaelHB func change. Link to comment Share on other sites More sharing options...
swh2u Posted June 30, 2016 Author Share Posted June 30, 2016 Got it! Local $oObject = _IEFormGetObjByName($oIE, "aspnetForm") Local $oEObject = _IEFormElementGetObjByName($oObject, $sHTML) ;$oObject.checked = False ; Uncheck the element $oEObject.checked = True ; Check the element Once again. Thanks for your help!!! Link to comment Share on other sites More sharing options...
MichaelHB Posted June 30, 2016 Share Posted June 30, 2016 Glad to know it worked. BTW you probably can do something like this (no need to grab the form element): Local $oObject = _IEGetObjByName($oIE, $sHTML) $oObject.checked = True ; Check the element Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now