• 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.

Hit button or call function on web page load and save file from displayed page

I have code where IE loads the web page, calls java function.
But I am unable to hit button or call associated function. Then I want to save .csv file from displayed page.
Thanks in advance.
Code:
Option Explicit
Sub SaveHTml1()
Dim str1, str2, str3, str7, URL As String
Dim ie, frm As Object
Dim i As Long
Dim FileName As String
Dim FF As Integer
'Dim elems As IHTMLInputTextElement
Dim wb As WebBrowser
Dim objElement As Object
Dim objCollection As Object
Dim button As Object

On Error Resume Next
Application.ScreenUpdating = False



URL = "https://webtac.industrysoftware.automation.siemens.com/webpr/webpr.php?objtype=frames&g_userid=a3rgcw&g_session_id=7302840" 'for TEST

'URL = Range("A" & i) 'for TEST
FileName = "C:\Users\" & Environ("UserName") & "\Desktop\" & Range("B" & i) & ".xml"

Set ie = CreateObject("Internetexplorer.Application")
ie.Visible = True
ie.Navigate URL

Do Until ie.ReadyState = 4
DoEvents
Loop

ie.Navigate ("javascript:parent.gotoSearch('advanced');")

str1 = "31 - Jan - 2001"
str2 = "28 - Nov - 2017"
str3 = "NX"
str7 = "External"


ie.Document.getelementsbyname("openedFrom_dateText")(0).Value = str1
ie.Document.getelementsbyname("openedTo_dateText")(0).Value = str2
ie.Document.getelementsbyname("product_family")(0).Value = str3
ie.Document.getelementsbyname("pr_type")(0).Value = str7

Do
Loop While ie.Busy

'Call ie.Document.getElementsByTagName("ok").Item(1).Click
'Set button = ie.Document.getElementById("ok")
'button.Click
'Dim CurrentWindow As HTMLWindowProxy: Set CurrentWindow = ie.Document.Parent
'Call CurrentWindow.execScript("onSubmitFunction()")

ie.Document.all.Item
Call ie.Document.parentWindow.execScript("onSubmitFunction()", "JavaScript")

Do
Loop While ie.Busy

Set button = ie.Document.getElementById("ok")
button.Click

CreateObject("Scripting.FileSystemObject").CreateTextFile FileName

Do Until ie.ReadyState = 4
DoEvents
Loop

FF = FreeFile
Open FileName For Output As #FF

With ie.Document.body
    Print #FF, .outerHTML & .innerHTML
End With

Close #FF

ie.Quit
Set ie = Nothing
Application.ScreenUpdating = True
End Sub

Html button code:
Code:
<input type="button" name="ok" id="ok" value=" OK " onclick="onSubmitFunction()">

Csv file save code:
Code:
<a href="javascript:getResultDataFile('csv')">[Comma-Delimited Text (CSV)]</a>
 

Attachments

Hmm? Sorry, can't test your code as this requires account with Siemens.

However, this is for their GTAC automation? If so, it's far better to contact Siemens for their API documentation. From there, it's rather simple to make API call to their system to automate things, rather than piloting browser.
 
Hmm. You're right! But I am downloading large amount data when manually try, for one year, even Chrome does not load data. So thought of automation.
 
It's really cumbersome to download data manually for 10 years. It's not possible to get solution, if posssible, from GTAC, so can someone please help me.
 
Like I stated, Siemens use their own API for automation. Which does not require IE piloting at all.

Hence my suggestion to ask them for their API. I assume you are their customer and/or working for re-seller right? Since, that site is for their post sales processing/report. It's proprietary info, so people outside of their community will have very little to no clue.

Go to Siemens support forum for their TAC/API and ask there.
 
I did ask them, they are providing data. I can also download manually which requires some time but I was thinking automating it as we require data with different option like date or etc.
With above code it's just not hitting OK button (on second navigated web page).
 
Back
Top