PDA

View Full Version : Sleeper: Access Textbox and Button inside the form of a frame of a webpage



Learner89
10-09-2013, 11:45 PM
Dear All,

I am writing a macro to automate the filling up some data from excel to company website. I have changed the website name in this post for data protection purpose. The excel will login for different clients by using the combination of username and password for respective clients and then some data are required to be inserted in a text box on a web page, I think the text box is on a form and form is within an iframe, within the web page. Once the data is inserted into text box, one button (Submit), which is also on the same form, is to be clicked.

On the click of a button, the updated data appears on another section, I could not make out if it is an form or frame, which is under the abovementioned form. Once we are happy with the way data appears on the web page, we have to click another button (Update), which is on the same section, to finally updating the data on website.

I wrote the following code to login to the website and then to navigate to the web page where I have to fill up the performance numbers in a text box.

The first problem is how to access the text box inside the form from VBA so that the macro can write a number in that text box and how to access the button to submit the data. The HTML code, which can be seen on click of F12, is attached below.

The second problem is how to access the Update button inside the other section, so that the data will be finally uploaded.


Sub LoginToCorpAccount()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
.navigate "https://kvinvest.com/clients/perf/"

' "Submit" button is found but it has no name – that is why
‘I have gone through all the elements with Tagname “input”

Set objcollection = ie.document.getElementsByTagName("input")

i = 0
While i < objcollection.Length
Debug.Print objcollection(i).Name
If objcollection(i).Name = "login" Then
objcollection(i).Value = "silver2"

ElseIf objcollection(i).Type = "password" Then
objcollection(i).Value = "golden2"

Else
If objcollection(i).Type = "submit" Then
Set objElement = objcollection(i)
objElement.Click
GoTo NextStep

End If
End If
i = i + 1
Wend
NextStep:
‘navigate to the page to upade the data
.navigate "https://kvinvest.com/clients/perf/?action=CurrentMonth"

‘nevigate to the page by further clicking the required link appearing on the above page
ie.document.all.Item("server_clientr").Click

End With
ie.Quit
Set ie = Nothing
End Sub

The F12 view (HTML) of the web pages shows the following:
<iframe name="PerformanceFrame" id=" PerformanceFrame " src="?action=iframe" frameBorder="0" style="width: 0px; height: 0px;">
<form class="ssc-form" action="https://kvinvest.com/clients/perf/?action=template&tid=signal_server_consumer&noheader=true" method="post" jQuery1381351885765="3">
-<input name="call" type="hidden" value="ssc"/>
-<input name="type" type="hidden" value="subscribe"/>
-<input name="csrf" type="hidden" value="8888888889999999"/>
--<div style="margin-bottom: 3px;">
--<span class="ssc-data-help" rel="ssc-help-provider" jQuery1381351885765="8">
--<input name="server" id="ssc-subscribe-server" style="width: 150px;" type="text"/>
--<input name="" id="ssc-subscribe-apply" style="width: 70px;" type="submit" jQuery1381351885765="4" value="Open"/>



<div id="ssc-consumers-holder"/> - This the line which gets highlighted when I click on the section where the data appears after clicking the submit button, and from here Update button is to be clicked.

Thank you very much for all your help.