• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Trouble inspecting element using IE

shahin

Active Member
I've tried with a script to download an excel file from a webpage. To download that file, it requires a click on that file. I'm trying to get the first file from that page. However, when I run my script, It does click on that file but instead of "saving" or "opening" that file there is a pop up appears in the very bottom of that page giving three options: "Open","Save", and "Cancel". At this point I'm stuck. I can't inspect it using IE. IE lets me inspect all the other stuffs from that webpage other than what I mentioned. There is no such warning in chrome so I could not inspect it there as well.

This is my attempt so far:
Code:
Sub Download_File()
    Dim HTML As HTMLDocument, post As Object
  
    With CreateObject("InternetExplorer.Application")
        .Visible = True
        .navigate "https://www.ccee.org.br/portal/faces/pages_publico/o-que-fazemos/infomercado?_adf.ctrl-state=oi8fqj9jb_1&_afrLoop=401324887077895#!%40%40%3F_afrLoop%3D401324887077895%26_adf.ctrl-state%3Doi8fqj9jb_5"
        While .Busy = True Or .readyState <> 4: DoEvents: Wend
        Set HTML = .document
      
        Do: Set post = HTML.getElementById("botaoDadosgerais"): DoEvents: Loop While post Is Nothing
        post.Click
    End With
End Sub

This image below contains the pop up I was talking about:
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    28.2 KB · Views: 13
IE does not expose save as to API. You either have to use SendKeys, or trace request that's sent to get the file and use Winhttp to download file.

Another option (mentioned by Marc L in another forum) is UIAutomationClient. But I wouldn't recommend this, as it isn't really meant for use with VBA (it's meant for .Net) and can be very complicated process for what it's worth.
 
Hi !

I used last year UIAutomationClient to pilot easy webpage under Firefox / IE
with success on my computers but may not work on others …
Windows 10 seems to be an issue but I do not have the opportunity
to really inspect what's going on under this OS.
I tried to build some generic code in order to simplify its use but I fed up
'cause some UIAutomation inner features may not work on some pages
so my build became a too big Bertha with some workarounds …

Instead of clicking on a button, sometimes a request is called for
loading the data in memory forward Excel or to be saved on hard disk.

Or by piloting IE, using some Windows dll to detect the little band
before to send some keys …
Sometimes a classic temporization can do the job
via Sleep as VBA Wait can be touchy
 
The workbook is directly opened in Excel on my side for this page
under IE11 / Windows 8.1 using UIAutomationClient
but as always I do not know precisely what you want to do …
And better than piloting IE is the request way.​
 

Same result with SendKeys under same computer,
just well observe how the webpage works with keyboard …​
 
Hi Marc L, I'm not familiar with this "UIAutomationClient". So, I don't know how to play with it. However, my intention was to save the "xl" file without manual intervention. That's it. Thanks.
 
Doc is on MSDN website …

So easy via sending keys : first surf on this webpage and
once the button has the focus and just after you click on it,
forget your mouse and just observe which is
the keyboard characters sequence needed for your need …
 
Found another one which is more or less similar to this existing issue. With the below script I tried to click on a link which is connected to an "xl" file. It does nothing as well:

Code:
Sub Get_File()
    Dim HTML As HTMLDocument, post As Object, LINK$
    LINK = "https://www.baseball-reference.com/play-index/batter_vs_pitcher.cgi?batter=mancitr01#site_menu_link"
   
    With CreateObject("InternetExplorer.Application")
        .Visible = False
        .navigate LINK
        While .Busy = True Or .readyState < 4: DoEvents: Wend
        Set post = .document.getElementById("dlink")
        post.Click
    End With
End Sub

See the image below in which I tried to show where I wanna trigger a click:
 

Attachments

  • 2CyNR.jpg
    2CyNR.jpg
    41.5 KB · Views: 5
Back
Top