PDA

View Full Version : Help with IE Button Click - SHDocVw



jmack81
02-17-2018, 08:13 PM
Hello - I've searched quite a bit and I'm having trouble executing a simple vba button click in IE. To take it a step further, the button id changes on refresh. Any thoughts? I am not new to vb but this is certainly not my wheelhouse. I am trying to upload a doc to a site but I need to start with the "upload" button.

The HTML is:


<button type="button" tabindex="0" id="upload_campaign_btn1518922861874-button">Upload</button>

bradl822
02-17-2018, 10:45 PM
If the ID is changing we would need better information, if you link to the upload site I should be able to advise.

yujin
02-18-2018, 01:05 AM
How about this?


For Each Obj In ObjIE.document.getElementsByTagName("button")
If Obj.innertext = "Upload" Then
Obj.Click
End If
Next

jmack81
02-18-2018, 10:17 AM
I’ll be a happy guy if this works! I’m going to try here in a bit. Thank you!!
Everything I read seems to relate to form filling or elements within <input> tags for which this does not have. I can reverse understand code to apply to my application but creating functions I’ve never done is not my thing.


How about this?


For Each Obj In ObjIE.document.getElementsByTagName("button")
If Obj.innertext = "Upload" Then
Obj.Click
End If
Next

jmack81
02-18-2018, 11:38 AM
If the ID is changing we would need better information, if you link to the upload site I should be able to advise.

You would need credentials to access it but I can post some of the source if it would help. I can pm some info as well since I need help and I know you need more info to provide any.

I have more to do with this project so I appreciate any help you can offer. I should be good once I get started.

jmack81
02-18-2018, 05:32 PM
So what I've got is a YUI library button that changes the visibility of a form. Is there anything different about working with these in VBA? I cannot select these or control them with what I am doing now.

yujin
02-18-2018, 10:12 PM
We need more HTML source code that is related to the button.

jmack81
02-19-2018, 03:14 PM
We need more HTML source code that is related to the button.


I know you're right. Maybe I can PM you some of what you need. If you're willing, that is. I do need help. I am able to navigate where I can find objects but this thing is kicking my butt. I'm using the selenium library at the moment and downgraded tools to try and track it. PITA!

jmack81
02-21-2018, 02:55 PM
So I figured this out the other night and thought I'd share the solution. I'm sure it's obvious to most but it had me stumped. The issue I was facing, was the element I was attempting to interact with was set in an iFrame and therefore not present in my initial scrape. My solution was a queryselector in a few different ways. I shared my current code so at least those that were trying to help can tell me this is good or poke some fun if they like. I don't actually run it like this as my variables are defined elsewhere but I pulled them in for the snip.

I'm finishing it up tonight and I need to navigate a file browser to select a file. I can locate it just fine and I think UIAutomation will take care of that but as always, I'm open to suggestion. I am not good at this.


Public xBrowser As New SHDocVw.InternetExplorerPublic xUserName As String
Public xPassword As String
Public xClientCode As String
Public xSheet As Worksheet
Public xURL As String
With New SHDocVw.InternetExplorer




Public Sub xCampUpload()


xURL = "My Url"


xLogin = "My Url login page"

xBrowser.Visible = True


xBrowser.navigate xURL


Do Until xBrowser.Busy = False And xBrowser.readyState = READYSTATE_COMPLETE: DoEvents: Loop

With xBrowser.document

Set xSheet = Sheets("Info")

xClientCode = xSheet.Range("B4").Value

xUserName = xSheet.Range("B5").Value

xPassword = xSheet.Range("B6").Value

.querySelector("*[id='client_code']").Value = xClientCode

.querySelector("*[id='user']").Value = xUserName

.querySelector("*[id='pass']").Value = xPassword

.querySelector("*[id='loginButton']").Click



xBrowser.navigate xURL

Do Until xBrowser.Busy = False And xBrowser.readyState = READYSTATE_COMPLETE: DoEvents: Loop

.querySelector("*[id='configure']").Click

.querySelector("*[id='campaign-label']").Click

.querySelector("*[id='upload_campaign-button']").Click

.querySelector("*[class='inputFileName']").Click

xFileSelect

End With

' End With

End Sub

ashleyuk1984
02-22-2018, 02:02 AM
How about this?


For Each Obj In ObjIE.document.getElementsByTagName("button")
If Obj.innertext = "Upload" Then
Obj.Click
End If
Next



This is the route that I usually take as well.