PDA

View Full Version : [SOLVED:] Automating selection of checkboxes in SSRS by label name



terdfurgeson
10-09-2015, 06:08 AM
Long story short, using VBA I'm trying to automate the selection of items from multi-value dropdown boxes and run SQL Server Reporting Services (SSRS).

I'm able to get to the page and start to make selections, but I need to check if the element's LABEL equals a certain value. I seem to be unable to locate a simple way to snag the label, as innertext and innerhtml seem to return blank spaces. The goal will be to have a list of names in Excel to match by elementID LABELS and then run the data.

If anyone has a method to scrape the label names for these, I'd LOVE to be able to incorporate it. Any assistance will be highly appreciated.



Sub UM51f()
Dim objIE, element
Dim SSRS As String
Set objIE = CreateObject("InternetExplorer.Application")
SSRS = [Link to SSRS here]
With objIE
.Visible = True
.navigate SSRS
Do Until .readyState = 4
DoEvents
Loop
.navigate [specific SSRS report link here]
Do Until .readyState = 4
DoEvents
Loop
'drop down for selection
Set element = .document.getelementbyid("ctl32_ctl04_ctl03_ddDropDownButton")
element.Click
'This is where I need to check to see if the element's label = a specific name:
Set element = .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl02")
'trying to print the values to see if they contain usable info:
Debug.Print .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl02").innertext
Debug.Print .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl02").innerhtml
element.Click
'More selections:
Set element = .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl03")
element.Click
Set element = .document.getelementbyid("ctl32_ctl04_ctl03_divDropDown_ctl04")
element.Click
End With
'A few more steps and then submit
End Sub


Sample script data I'm referencing:

<table cellpadding="0" cellspacing="0" style="background-color:window;">
<tr>
<td nowrap="nowrap"><span><input id="ctl32_ctl04_ctl03_divDropDown_ctl00" type="checkbox" name="ctl32$ctl04$ctl03$divDropDown$ctl00" onclick="$get('ctl32_ctl04_ctl03').control.OnSelectAllClick(this);" /><label for="ctl32_ctl04_ctl03_divDropDown_ctl00">(Select All)</label></span></td>
</tr><tr>
<td nowrap="nowrap"><span><input id="ctl32_ctl04_ctl03_divDropDown_ctl02" type="checkbox" name="ctl32$ctl04$ctl03$divDropDown$ctl02" onclick="$get('ctl32_ctl04_ctl03').control.OnValidValueClick(this, 'ctl32_ctl04_ctl03_divDropDown_ctl00');" /><label for="ctl32_ctl04_ctl03_divDropDown_ctl02">Name1</label></span></td>
</tr><tr>
<td nowrap="nowrap"><span><input id="ctl32_ctl04_ctl03_divDropDown_ctl03" type="checkbox" name="ctl32$ctl04$ctl03$divDropDown$ctl03" onclick="$get('ctl32_ctl04_ctl03').control.OnValidValueClick(this, 'ctl32_ctl04_ctl03_divDropDown_ctl00');" /><label for="ctl32_ctl04_ctl03_divDropDown_ctl03">Name2</label></span></td>
</tr><tr>

terdfurgeson
10-09-2015, 06:12 AM
Oh, and this is in IE8. Forgot to include that in the original post

terdfurgeson
10-09-2015, 08:52 AM
I suppose one method could be to extract the Script text and write a small search function? If I went this route, is there a good method to obtain the script source in a way that VBA can search it? I've done this with HTML, but very unsure how to in this situation.

SamT
10-09-2015, 09:17 AM
For="ctl32_ctl04_ctl03_divDropDown_ctl00">(Select All)</label>

http://www.w3schools.com/jsref/dom_obj_label.asp :html For Sets or returns the value of the for attribute of a label



:dunno Maybe

X = document.getElementById("ctl32_ctl04_ctl03_divDropDown_ctl00").getAttribute("Label").InnerText

terdfurgeson
10-09-2015, 10:32 AM
Thanks for the reply. Unfortunately testing with the following produced a 424 Object Required error.


Debug.Print .document.getElementById("ctl32_ctl04_ctl03_divDropDown_ctl00").getAttribute("Label").InnerText

terdfurgeson
10-12-2015, 03:09 PM
I made an ugly method to get me what I needed. It uses sendkeys, but so far it hasn't had an error after about 25 tests.

In short, the code opens IE and gets to the report page
SendKeys simulates F12 to open Dev tools
More sendkeys to get to the Script tab and select/copy it.
Open Notepad
Paste
Save and close

Back in IE, iterate through each of the checkboxes by id to see if the label (name) is on a list. If so, check the box.
then finish the report and export..


Appreciate the help, thought I'd give my .02 should someone else be looking to do something similar. I don't like using sendkeys, but so fat after about 25 tests, it seems to preform this task ok.

SamT
10-12-2015, 03:57 PM
Thanks for sharing your solution.

ashleyrobbin
11-15-2015, 05:22 AM
thanks!:hi: