Our company uses a browser-based program for business operations. My goal is to grab some data out of this system automatically.
The site itself uses frames pretty heavily, but I'm doing pretty decently handling that. The problem in front of me now is navigating to the screen on which my data is housed.
The link itself is coded in javascript, and I don't see an anchor tag (The image is a +/-, or invisible for spacing):
Source Code
<div id='Nav_4' aTag='aTarget' title='Target' aUrl="javascript:top.aaa.submitPage('NavigateTo','~/aPages/aPage.aspx?UC=a')">
<img alt='' style="margin-left:0px; width:0px "/>
<img src='/a/a.axd?d=a' alt='(Collapsed)' aAltX='(Expanded)' imgType='exp' />
<img alt=''style='width:5px; visibility:hidden;'>
<span atxt='1' class=" breadcrumbTreeItem">
Target
</span></div>
Since I couldn't get the a tag, or search the document for Links, I instead tried to find the span tag that contained "Target" and try to activate it.
Here is the working code! (i5 is an iterator)
Set ie = GetOpenIEByURL("https://aaa.com/AAA.htm")
fIter = 0
For Each frmSet In ie.document.getElementsByTagName("Frame")
If Left(frmSet.src, 7) = "aaa/AAA" Then
myFrame = f_Iter
Exit For
End If
f_Iter = f_Iter + 1
Next
With ie
For i5 = 0 To ie.document.frames(myFrame).document.all.tags("SPAN").Length - 1
With .document.frames(myFrame).document.all.tags("SPAN").Item(i5)
If InStr(.innerText, "Target") > 0 Then
.Click
Exit For
End If
End With
Next i5
End With
Additionally, in the Module, add this code:
'Finds an open IE site by checking the URL
Function GetOpenIEByURL(ByVal i_URL As String) As InternetExplorer
Dim objShellWindows As New ShellWindows
'ignore errors when accessing the document property
On Error Resume Next
'loop over all Shell-Windows
For Each GetOpenIEByURL In objShellWindows
'if the document is of type HTMLDocument, it is an IE window
If TypeName(GetOpenIEByURL.document) = "HTMLDocument" Then
'check the URL
If Left(GetOpenIEByURL.document.URL, 30) = Left(i_URL, 30) Then
'leave, we found the right window
Exit Function
End If
End If
Next
End Function