• 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 on web page using vba

I wanted to hit button on web page so that second web page will be loaded and I can save the whole source code of that web page. Right what I have is:

Code:
Option Explicit
Sub SaveHTML()
Dim str, 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

str = Sheets("Sheet1").Range("J1").Value
URL = "https://tiweb.industrysoftware.automation.siemens.com/prdata/cgi-bin/n_prdata_index.cgi" 'for TEST
FileName = "C:\Users\a3rgcw\Downloads\7946412\7946412\Test.htm"

Set IE = CreateObject("Internetexplorer.Application")
IE.Visible = True
IE.Navigate URL
Do
Loop While IE.Busy

    IE.Document.getElementsByName("pr_numbers")(0).Value = str
    Application.SendKeys ("~")
   
' Need button click code here

CreateObject("Scripting.FileSystemObject").Createtextfile FileName

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
End Sub

And web page source code for button is:
Code:
<td style="border:solid 1px #060; border-left: none">
<textarea name="pr_numbers" rows="5" cols="22" >
</textarea>
<br>
<button onClick="return check_mvsub(this)">
<br>
<b>
Search and Download
</b>
<br>
</button>
</td>
</tr>
 

Attachments

  • Capture.PNG
    Capture.PNG
    8.9 KB · Views: 3
Hi,

Application.SendKeys ("~") is basically hitting "Enter".

Wasn't it working before?

Anyway, if it isn't working, either locate the button ID (inspect button in browser and search in properties) and then use it in:
Code:
Dim Button As Object
Set Button = IE.Document.getElementByID("Button ID here!")
Button.Click

or try something like:
Code:
IE.Document.ExecScript("return check_mvsub(this)","javascript")

See if any of these work.
 
Back
Top