UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> File Browser In Ie Freezes Code, Access 2010    
 
   
AdrianThorn
post Mar 13 2018, 04:37 PM
Post#1



Posts: 29
Joined: 1-December 15



I am writing a script that will automate the upload of some shapefiles to a confidential website. I've hit a snag during the final step of the process - specifying the location of each file. The page contains an element which does not accept text, rather you have to click it and it opens a file browser. The pertinent code:

CODE
<input name="FileUpload1" id="FileUpload1" type="file">


My script opens the file browser like so:

CODE
IE.Document.GetElementsByName("FileUpload1")(0).Click


After which it immediately stops running and spits out this error:

"This action cannot be completed because the Upload a Shapefile - Internet Explorer application (Upload a Shapefile - Internet Explorer) is not responding. Choose Switch To to activate Upload a Shapefile - Internet Explorer and correct the problem."

I'm at a loss as to why this is occurring or how to get around it. I can't find a way to suppress the dialogue nor can I interact with it because nothing runs after it opens. Any suggestions?
Go to the top of the page
 
DanielPineault
post Mar 13 2018, 04:52 PM
Post#2


UtterAccess VIP
Posts: 5,962
Joined: 30-June 11



It should make no difference, but what happens if you do something more along the lines of

CODE
    Set oFileUpload= IE.Document.getelementbyid("FileUpload1")
        oFileUpload.Click


You've made sure the page isn't busy at the time of clicking the button, and it finished loading prior to starting to interact with it.




Another potential approach would be to identify it's element number within the form and do something like

CODE
     IE.Document.Forms(0).elements(12).Click


You get the general idea.

You can use a function like the following one to extract the elements and their respective numbers

CODE
Public Sub List_URLFormElementDetails(sURL as String)
On Error Resume Next
    'Navigate to a URL and output details of forms and form elements to Immediate Window
    Dim URL As String
    Dim IE As Object
    Dim f As Integer
    Dim e As Integer
    
    Set IE = CreateObject("InternetExplorer.Application")
    
    With IE
        .Visible = True
        .Navigate sURL
        Do While .Busy Or .readyState <> 4: DoEvents: Loop
    End With
    
    Debug.Print "IE.document.forms.Length=" & IE.Document.Forms.Length

    For f = 0 To IE.Document.Forms.Length - 1
        With IE.Document.Forms(f)
            Debug.Print vbNewLine & "IE.document.forms(" & f & ")"
            Debug.Print "  .Name=" & .Name & " .ID=" & .ID & " .action=" & .Action & " .method=" & .method
            Debug.Print "  .elements.Length=" & .elements.Length
        End With
        
        For e = 0 To IE.Document.Forms(f).elements.Length - 1
            With IE.Document.Forms(f).elements(e)
                Debug.Print "  .elements(" & e & ")"
                Debug.Print "    .tagName=" & .tagName & " .Name=" & .Name & " .ID=" & .ID & " .Value=" & .Value
            End With
        Next    Next
    
    Set IE = Nothing
End Sub






For a weird issue, similar to this, I once had to do something like

CODE
        Set ElementCol = IE.Document.getElementsByTagName("INPUT")
         For Each btnInput In ElementCol
             If btnInput.Name = "FileUpload1" Then
                 btnInput.Click
                 Exit For
             End If
         Next btnInput






--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
AdrianThorn
post Mar 13 2018, 05:01 PM
Post#3



Posts: 29
Joined: 1-December 15



Yes a:

CODE
Do While IE.Busy
Loop


comes before and after the click. I made your changes as suggest and it didn't impact the problem. I'll see if I can identify the element number and report back.
Go to the top of the page
 
AdrianThorn
post Mar 13 2018, 05:07 PM
Post#4



Posts: 29
Joined: 1-December 15



Found the element number (3), same issue.
Go to the top of the page
 
AdrianThorn
post Mar 13 2018, 07:07 PM
Post#5



Posts: 29
Joined: 1-December 15



Forgot the entire code - here it is:

CODE
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim SWs As ShellWindows ''Requires Microsoft Internet Controls
Dim oWShell As Object

Set db = CurrentDb
Set SWs = New ShellWindows

'Open Internet Explorer
Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True
    
'Open NMCRIS
IE.Navigate 'main page
TabNum = SWs.Count

'Wait for the page to load
Do While IE.Busy
Loop
        
'Enter in login credentials
Set objCollection = IE.Document.GetElementsByTagName("input")
objCollection(8).Value = 'username
objCollection(9).Value = 'password


CTime = Time
GTime = DateAdd("s", 1, CTime)
    
Do Until CTime >= GTime
    CTime = Time
Loop
    
Do While IE.Busy
Loop
    
'Click the login button
IE.Document.getElementsByClassName("button_link")(0).Click

CTime = Time
GTime = DateAdd("s", 1, CTime)
    
Do Until CTime >= GTime
    CTime = Time
Loop

Do While IE.Busy
Loop

'Do Until a = 208
    'Navigate to the Resource list
    IE.Navigate 'site URL
    
    Do While IE.Busy
    Loop
    
    CTime = Time
    GTime = DateAdd("s", 2, CTime)
    
    Do Until CTime >= GTime
        CTime = Time
    Loop
    
    'Find the site
    IE.Document.getElementsByClassName("Search_Input")(0).Value = Replace(site_array(0), "LA_", "")
    '''''Find the activnity IE.Document.getElementsByClassName("Search_Input")(1).Value = "139788"
    
    CTime = Time
    GTime = DateAdd("s", 1, CTime)
    
    Do Until CTime >= GTime
        CTime = Time
    Loop
    
    Do While IE.Busy
    Loop
      
    'Press the search button
    IE.Document.getElementsByClassName("button_link")(0).Click

    Do While IE.Busy
    Loop
    
    CTime = Time
    GTime = DateAdd("s", 3, CTime)
    
    Do Until CTime >= GTime
        CTime = Time
    Loop

    'Find the site which matches our Activity number, then open the GIS page
    Set objCollection = IE.Document.getElementsByClassName("ttc")
    i = 0

    Do Until i = objCollection.Length
        If InStr(objCollection(i).InnerText, nmcris_activity) > 0 Then
            n = i + 2
            Set objElement = objCollection(n).firstElementChild
        End If
        i = i + 1
    Loop

    objElement.Click
    
    Do While IE.Busy
    Loop

    CTime = Time
    GTime = DateAdd("s", 5, CTime)
    Do Until CTime >= GTime
        CTime = Time
    Loop

    'Switch to the GIS tab
    With CreateObject("Shell.Application").Windows
        Set IE = .Item(SWs.Count - 1)
    End With

    'Open the editor menu
    
    IE.Document.getElementsByClassName("TaskMenu_1 TaskMenu_3 TaskMenu_7")(0).Click
    
    CTime = Time
    GTime = DateAdd("s", 1, CTime)
    Do Until CTime >= GTime
        CTime = Time
    Loop

    Do While IE.Busy
    Loop
    
    'Check to see if the site needs a new shapefile or if we are updating one.
    Set objCollection = IE.Document.GetElementsByName("TaskManager1$EditorTask1$Editor$nmcrisEditPanel$ddSites")
    GIStatus = Null
    i = 0

    Do Until i = objCollection.Length
        If objCollection(i).ID = "TaskManager1_EditorTask1_Editor_nmcrisEditPanel_ddSites" Then
            GIStatus = objCollection(i).Value
            Set objElement = objCollection(i)
        End If
    
        i = i + 1
    Loop

    If IsNull(GIStatus) = True Then
        'Need to create the shape file
    Else
        'Need to update the shaple file.  Activate edits.
        IE.Document.GetElementsByName("TaskManager1$EditorTask1$Editor$nmcrisEditPanel$btnEditSite")(0).Click
        
        CTime = Time
        GTime = DateAdd("s", 1, CTime)
        Do Until CTime >= GTime
            CTime = Time
        Loop
    
        Do While IE.Busy
        Loop
    
        'Wait for the confirmation box to appear, then hit OK
        Set oWShell = CreateObject("wscript.shell")

        Do Until oWShell.AppActivate("Message from webpage")
            CTime = Time
            GTime = DateAdd("s", 0.1, CTime)
            Do Until CTime >= GTime
                CTime = Time
            Loop
        Loop
            
        oWShell.SendKeys "{enter}"
        
        CTime = Time
        GTime = DateAdd("s", 1, CTime)
        Do Until CTime >= GTime
            CTime = Time
        Loop
    
        Do While IE.Busy
        Loop
        
        'SendKeys "~"
        
        'Open up the uploading dialogue
        IE.Navigate ''another URL
        
        Do While IE.Busy
        Loop
        
        CTime = Time
        GTime = DateAdd("s", 2, CTime)
        Do Until CTime >= GTime
            CTime = Time
        Loop
    

        'Input the shape file locations

        CTime = Time
        GTime = DateAdd("s", 1, CTime)
        Do Until CTime >= GTime
            CTime = Time
        Loop
        
IE.Document.GetElementsByName("FileUpload1")(0).Click
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    16th July 2018 - 10:57 PM