I am working on writing some VBA code to automate filling out a ticket web form.
The piece of this I am currently stuck on is the clicking of a dynamic (search result driven) A HREF tag link that contains what I believe is some AJAX code.
On the web form, you enter an asset number into a search box and you click on the "Search" button. This brings up a list of possible matches as a search result on the page. I have automated adding the asset automatically from my Excel spreadsheet in the textbox and executing the clicking of the "Search" button. The search result link appears on the page (and because there is only one matching asset in the database, only one search result appears).
The link display text for that hyperlink is equal to the asset number and the code for this link is: < a href="javascript:void(0);" *******="AUL.update('AssignedAssetsUpdateContainer', {}, '12.7.21.0.0.0.0.2.3.0.0.1.2.0.3.0.1.5.5.0.1.3.1.5.0.0.1.2.9.5.1.19.0.1.3.1');" >168358< /a >
I've tried two approaches in trying to click this link so far:
Count = 0
For Each l In ie.Document.getElementsByTagName("a")
If l.href = "javascript:void(0);" Then
Count = Count + 1
If Count = "6" Then
l.Click
GoTo ClickTicketDetailsButton
End If
End If
Next
There are five other links on this page that contains the last five assets I've searched for and attached to tickets. The dynamic search result link should be number 6. However, while this approach works perfectly for those first five links, it fails when trying to identify and click the search result link.
The other approach I've been playing with is to execute the JavaScript ******* event directly using: Call CurrentWindow.execScript("AUL.update('AssignedAssetsUpdateContainer', {}, '280.7.21.0.0.0.0.2.3.0.0.1.2.0.3.0.1.5.5.0.1.3.1.5.0.0.1.2.9.5.1.19.0.1.3.1');")
The first number appears to be random while the other numbers remain fixed.
This approach works when I step the code and I can manually change the (what is this number called, is this a session ID?) ID to match, but as this number changes each time the page is refreshed (and possible every time the search is conducted). Is there a way through code to pull/identify this number using VBA and then insert it back into the Call CurrentWindow.execScript statement?
Here is how I am establishing my connection to the website.
' Add reference to Microsoft Internet Controls (SHDocVw)
' Add reference to Microsoft HTML Object Library
Sub TriggerDivClick()
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim div
Dim url As String
Dim Tags As Object
Dim Tagx As Object
Dim LastName As Object
Dim Count
Dim l
'Automate The Creation Of The Web Help Desk Ticket
'URL For The Ticketing System
url = "https://help.psdschools.org/helpdesk/WebObjects/Helpdesk.woa"
'Create InternetExplorer Object
Set ie = New SHDocVw.InternetExplorer
'Make Internet Explorer Visible
ie.Visible = True
'Go to UR Specified Above
ie.Navigate url
'Wait Until Internet Explorer Is Not Busy
While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
If there is any other info that would be helpful, please let me know.
Thanks much!
-Matt-
The piece of this I am currently stuck on is the clicking of a dynamic (search result driven) A HREF tag link that contains what I believe is some AJAX code.
On the web form, you enter an asset number into a search box and you click on the "Search" button. This brings up a list of possible matches as a search result on the page. I have automated adding the asset automatically from my Excel spreadsheet in the textbox and executing the clicking of the "Search" button. The search result link appears on the page (and because there is only one matching asset in the database, only one search result appears).
The link display text for that hyperlink is equal to the asset number and the code for this link is: < a href="javascript:void(0);" *******="AUL.update('AssignedAssetsUpdateContainer', {}, '12.7.21.0.0.0.0.2.3.0.0.1.2.0.3.0.1.5.5.0.1.3.1.5.0.0.1.2.9.5.1.19.0.1.3.1');" >168358< /a >
I've tried two approaches in trying to click this link so far:
Count = 0
For Each l In ie.Document.getElementsByTagName("a")
If l.href = "javascript:void(0);" Then
Count = Count + 1
If Count = "6" Then
l.Click
GoTo ClickTicketDetailsButton
End If
End If
Next
There are five other links on this page that contains the last five assets I've searched for and attached to tickets. The dynamic search result link should be number 6. However, while this approach works perfectly for those first five links, it fails when trying to identify and click the search result link.
The other approach I've been playing with is to execute the JavaScript ******* event directly using: Call CurrentWindow.execScript("AUL.update('AssignedAssetsUpdateContainer', {}, '280.7.21.0.0.0.0.2.3.0.0.1.2.0.3.0.1.5.5.0.1.3.1.5.0.0.1.2.9.5.1.19.0.1.3.1');")
The first number appears to be random while the other numbers remain fixed.
This approach works when I step the code and I can manually change the (what is this number called, is this a session ID?) ID to match, but as this number changes each time the page is refreshed (and possible every time the search is conducted). Is there a way through code to pull/identify this number using VBA and then insert it back into the Call CurrentWindow.execScript statement?
Here is how I am establishing my connection to the website.
' Add reference to Microsoft Internet Controls (SHDocVw)
' Add reference to Microsoft HTML Object Library
Sub TriggerDivClick()
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim div
Dim url As String
Dim Tags As Object
Dim Tagx As Object
Dim LastName As Object
Dim Count
Dim l
'Automate The Creation Of The Web Help Desk Ticket
'URL For The Ticketing System
url = "https://help.psdschools.org/helpdesk/WebObjects/Helpdesk.woa"
'Create InternetExplorer Object
Set ie = New SHDocVw.InternetExplorer
'Make Internet Explorer Visible
ie.Visible = True
'Go to UR Specified Above
ie.Navigate url
'Wait Until Internet Explorer Is Not Busy
While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
If there is any other info that would be helpful, please let me know.
Thanks much!
-Matt-
Last edited: