Sign in to follow this  
Followers 0
swh2u

Check Value in Check Box based on Label

11 posts in this topic

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?

 

 

Capture.PNG

Share this post


Link to post
Share on other sites



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. 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Hi @MichaelHB,

No the data changes when another element is added.  not the same each time but loaded into the ID.  

Steve

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by MichaelHB
spell

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by swh2u

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by swh2u

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

First you have to notice that you are not grabbing the form object. Remember the common order:

  1. oIE = IE object.
  2. oForm = Form element inside the oIE.
  3. 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 by MichaelHB
func change.

Share this post


Link to post
Share on other sites

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

 

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