Consulting

Results 1 to 10 of 10

Thread: Help with IE Button Click - SHDocVw

  1. #1
    VBAX Regular
    Joined
    Apr 2016
    Posts
    9
    Location

    Help with IE Button Click - SHDocVw

    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>

  2. #2
    VBAX Newbie
    Joined
    Nov 2017
    Posts
    2
    Location
    If the ID is changing we would need better information, if you link to the upload site I should be able to advise.

  3. #3
    VBAX Regular
    Joined
    Jan 2018
    Posts
    55
    Location
    How about this?

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


  4. #4
    VBAX Regular
    Joined
    Apr 2016
    Posts
    9
    Location
    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.

    Quote Originally Posted by yujin View Post
    How about this?

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


  5. #5
    VBAX Regular
    Joined
    Apr 2016
    Posts
    9
    Location
    Quote Originally Posted by bradl822 View Post
    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.

  6. #6
    VBAX Regular
    Joined
    Apr 2016
    Posts
    9
    Location
    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.

  7. #7
    VBAX Regular
    Joined
    Jan 2018
    Posts
    55
    Location
    We need more HTML source code that is related to the button.

  8. #8
    VBAX Regular
    Joined
    Apr 2016
    Posts
    9
    Location
    Quote Originally Posted by yujin View Post
    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!

  9. #9
    VBAX Regular
    Joined
    Apr 2016
    Posts
    9
    Location
    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

  10. #10
    Quote Originally Posted by yujin View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •