PDA

View Full Version : Web Automation (Excel+VBA) - Help checking element in table



firebirdta84
10-21-2016, 07:20 AM
Hi All -

I am attempting to use Excel and VBA for some web automation. I've got a good portion of it working properly, but I am having an issue with one final step.

This code opens up a new IE window, navigates to a website, enters in criteria in a search field and clicks the Search button.

At this point, the website opens up to a search results pages, where the results are housed in a table. Column 1 is a checkbox and column 2 is a clickable link.

The above steps all work perfectly in my code. Here's where I need help:

I need my code to search through the clickable links in Column 2. When it finds the link with the display name "REL", it needs to check the corresponding checkbox in Column 1 of that row, and then click on the "REL" clickable link.

Below is my VBA code:


Private Sub Test()
Dim casenumber As Variant
casenumber = "1234"
the_start:
'Set objIE = CreateObject("InternetExplorer.Application")
Set objIE = New InternetExplorerMedium
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.Visible = True
objIE.Navigate ("http...")
Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
Set alllinks = objIE.document.getElementsByTagName("A")
For Each Hyperlink In alllinks
If InStr(Hyperlink.innerText, "FLAG") > 0 Then
Hyperlink.Click
Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop
GoTo ResumeEntry
End If
Next
ResumeEntry:
objIE.document.getElementById("caseNumber").Value = casenumber
objIE.document.getElementById("filterdocs").Click
End Sub
And here is the website's HTML. I expanded the code that relates to the row in the table containing the "REL" clickable link:


<table><tbody><tr/><tr/><tr/><tr/><tr/><tr/><tr/><tr><td><label for="doc792548110407"><input id="doc792548110407" type="checkbox" title="Search Result: Checkbox" class="case1234"/></label></td><td class=""><div><a rel="nofollow" target="_blank" href="/iwa/docs/viewer/view?set0=792548110407,workspace-c!--s!--s!-SpacesStore-s!-3123dfc4-125b-4dfa-aa86-8979c73b9d82,1,REL,1234,OPEN,1474013488319" id="viewPages792548110407">REL</a></div></td><td>1</td><td>Open</td><td>09/06/2016</td><td style="color: green;">R</td></tr><tr/><tr/><tr/><tr/><tr/></tbody></table>

Thanks in advance!
Joe