What I'm trying to do is get the handle of the button that I'm trying to click. however there are two URLs 1st is the main URL which is in the window and 2nd is the URL inside the window (when you right click > Properies the button the URL is different from the main windows'). Also it is different or 2nd HTML Document (note: there's no iframe/frame.)
only the 2nd URL that is I cannot get the handle in order for me to control its elements.
I already tried some codes below to get all handles.
ConnectURL "Secondary URL"
GetTheWindowHandle "IEFrame", "Secondary URL - Internet Explorer", hwndp
SetForegroundWindow hwndp
Sub ConnectURL(strURL As String)
On Error Resume Next
Set sws = New SHDocVw.ShellWindows
jar = sws.Count - 1
If jar < 0 Then
MsgBox "There's no active IE or window Explorer", vbInformation, "Pop-out"
Set sws = Nothing
Exit Sub
End If
n = 0
Do Until (n > 5000)
If (Left(sws.Item(n).LocationURL, Len(strURL)) = strURL) Then
If err.Number = 0 Then
Exit Do
End If
err.Clear
End If
n = n + 1
Loop
Set ieDoc = sws.Item(n).document
sws.Item(n).Visible = True
Set ieLoad = sws.Item(n)
End Sub
Function GetTheWindowHandle(C`enter code here`lassName As String, toSearch As String, handle As Long)
'Get Handle of window
tempHandle = 0
tempHandle = FindWindowEx(0, tempHandle, ClassName, vbNullString)
Do While tempHandle <> 0 'while handle is not seen
GetNameOfWindowByHandle tempHandle
If InStr(1, TextResult, toSearch) > 0 Then 'Check if Window title is similar
handle = tempHandle 'capture handle
Exit Do
End If
tempHandle = FindWindowEx(0, tempHandle, ClassName, vbNullString)
Loop
End Function
Function GetNameOfWindowByHandle(myHwnd As Long)
'capture the title of the window
Dim sbuffer As Long
Dim lresult As String
sbuffer = SendMessage(myHwnd, WM_GETTEXTLENGTH, 0, vbNullString)
sbuffer = sbuffer + 1
TextResult = Space$(sbuffer)
lresult = SendMessage(myHwnd, WM_GETTEXT, sbuffer, ByVal TextResult)
End Function
Example below
<div class="slit-item-active" id="reportsTab" onclick="openReportExplorer();"><div class="nav-icon3"></div><span id="reportsTabText">Reports</span></div>
this html code is on the button with the 2nd URL that I'm trying to get it's handle so i can use my code:
iedoc.getelementbyid("reportsTab").click
or
waiting = 0
Do While waiting = 0
For Each obj1 In ieDoc.getElementById("reportsTab").getElementsByTagName("span")
Debug.Print obj1.innerText
If Trim(obj1.innerText) = "Reports" Then
obj1.Click
ieLoading 2000
waiting = 1
Exit For
End If
Next
Loop
Aucun commentaire:
Enregistrer un commentaire