473,503 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access Textbox and Button inside the form of a frame of a webpage

4 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. Sub LoginToCorpAccount()    
  2.     Dim ie As Object
  3.     Set ie = CreateObject("InternetExplorer.Application")
  4.  
  5.     With ie
  6.         .Visible = True
  7.         .navigate "https://kvinvest.com/clients/perf/"        
  8.  
  9.         ' "Submit" button is found but it has no name – that is why
  10.         ‘I have gone through all the elements with Tagname “input”                    
  11.  
  12.         Set objcollection = ie.document.getElementsByTagName("input")
  13.  
  14.         i = 0
  15.         While i < objcollection.Length
  16.             Debug.Print objcollection(i).Name
  17.             If objcollection(i).Name = "login" Then        
  18.                 objcollection(i).Value = "silver2"
  19.  
  20.             ElseIf objcollection(i).Type = "password" Then
  21.                 objcollection(i).Value = "golden2"
  22.  
  23.             Else
  24.                 If objcollection(i).Type = "submit" Then        
  25.                     Set objElement = objcollection(i)
  26.                     objElement.Click
  27.                     GoTo NextStep
  28.  
  29.                 End If
  30.             End If
  31.             i = i + 1
  32.         Wend
  33. NextStep:          
  34. ‘navigate to the page to upade the data        
  35. .navigate "https://kvinvest.com/clients/perf/?action=CurrentMonth"
  36.  
  37. ‘nevigate to the page by further clicking the required link appearing on the above page
  38.                 ie.document.all.Item("server_clientr").Click         
  39.  
  40.     End With
  41.     ie.Quit
  42.     Set ie = Nothing
  43. End Sub
The F12 view (HTML) of the web pages shows the following:
Expand|Select|Wrap|Line Numbers
  1. <iframe name="PerformanceFrame" id=" PerformanceFrame " src="?action=iframe" frameBorder="0" style="width: 0px; height: 0px;">
  2. <form class="ssc-form" action="https://kvinvest.com/clients/perf/?action=template&tid=signal_server_consumer&noheader=true" method="post" jQuery1381351885765="3">
  3. -<input name="call" type="hidden" value="ssc"/>
  4. -<input name="type" type="hidden" value="subscribe"/>
  5. -<input name="csrf" type="hidden" value="8888888889999999"/>
  6. --<div style="margin-bottom: 3px;">
  7. --<span class="ssc-data-help" rel="ssc-help-provider" jQuery1381351885765="8">
  8. --<input name="server" id="ssc-subscribe-server" style="width: 150px;" type="text"/>
  9. --<input name="" id="ssc-subscribe-apply" style="width: 70px;" type="submit" jQuery1381351885765="4" value="Open"/>
  10.  
  11.  
  12.  
  13. <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.
Oct 10 '13 #1
6 10465
zmbd
5,501 Recognized Expert Moderator Expert
PLEASE!
Make sure that you use the [CODE/] format around ALL HTML, VBA, or other formatted text.

My company antivirus tripped a warning about this page as a possible IFRAME infection. Once I placed the [Code/] formatting around your posted HTML this warning went away!

It is very importaint that you comply with this site rule to prevent false positives with other member's and search engine's antivirus software.
Oct 10 '13 #2
VBAToexcel
4 New Member
Hi ZMBD,

Next time I will insert the [CODE/] format around all of the codes. I did not realized that I have to insert [CODE/]around all the codes.

I did not insert [CODE/] in first place as I didn't want that particular piece of codes to appear in that special window.

But anyway, I will take care from next time.

Thanks.
Oct 10 '13 #3
zmbd
5,501 Recognized Expert Moderator Expert
You're going to end up working with the DOM (document object model).
Unfortunately the one working example I have is on the Work PC and I won't have access to it until next Monday.
This document may help you with some of the basics document object (Internet Explorer)
I've not tried this with Firefox or other browsers.
There was a thread on this a few months back that I can find it I'll link it in here...

Basically, you will add a reference to the IE library and the Microsoft HTML Object Library (if you want to be able to do early bind and use the intelisense and built-in constaints). Then it's like any other office automation script. You'll need to find the element names on the HTML page that hold the data or execute the actions.

Sorry, I don't have the references here at home.
Oct 11 '13 #4
VBAToexcel
4 New Member
Hi ZmDB,

Thank you very much for your reply. I appreciate your time and effort.

I will go through the MSDN link and will try to resolve the issue. I will update the post accordingly.

But would you please post the working example here once you get hold of it on Monday.

With best regards.
Oct 11 '13 #5
zmbd
5,501 Recognized Expert Moderator Expert
VBAToexcel
-
I normally wouldn't post anything like the following; however, because you've beaten your head against the wall a few times and so have I in trying to figure out how to directly access webpages from within VBA in general, I came up with the following "Proof of Concept" code some time back and will share my "alpha-code."

Normally I’d just point you to the sources I found and send you off on your way to figure this out; however, it wasn’t until I found a few non-working examples and figured out what was going on that I came up with the following and finally found some information that actually helped.

It's not pretty coding... as I said, it is POC work cobbled together from several sources – it worked today, it may not work tomorrow

What should happen when the code is ran from a standard vba module: late-binds to the internet explorer application and creates the object; navigates to Google (during POC I needed a stable document); waits for the window to open; finds the data entry box and inserts my search string; clicks in the action control; and finally maximizes the window.
- This code is only valid for IE... I don't know how one would use any of the other browsers; thus, I'll be no help with that!
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3. '
  4. 'For latebind IE Object
  5. Public Enum READYSTATE
  6.         READYSTATE_UNINITIALIZED = 0
  7.         READYSTATE_LOADING = 1
  8.         READYSTATE_LOADED = 2
  9.         READYSTATE_INTERACTIVE = 3
  10.         READYSTATE_COMPLETE = 4
  11. End Enum
  12. '
  13. 'Need to get at the stuppid API to maximize the window after opening.
  14. 'may break under 64bit installs.
  15. 'borrowed this from somewhere...
  16. Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
  17.             (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
  18.  
  19. Global Const SW_MAXIMIZE = 3
  20. Global Const SW_SHOWNORMAL = 1
  21. Global Const SW_SHOWMINIMIZED = 2
  22.  
  23.  
  24. Sub ExampleDocumentObjectModel()
  25.     '
  26.     'based on: http://vba-corner.livejournal.com/4623.html.
  27.     '
  28.     'If you want to use the early binding to have access to all of the
  29.     'nice constants and intilisense then set a reference to:
  30.     'VBA/Editor/Tools/References.../[x]Microsoft Internet Controls
  31.     '
  32.     On Error GoTo errorjumppoint
  33.     Dim z_ie As Object
  34.     '
  35.     'Create a new internet explorer object. The Document above had all sorts
  36.     'of code to check for current IE objects and how to open within.
  37.     'for my needs and as POC just open a new IE
  38.     Set z_ie = CreateObject("InternetExplorer.Application")
  39.     '
  40.     'Let's use a webpage for POC that I know will be there
  41.     z_ie.Navigate "www.google.com"
  42.     '
  43.     'Loop until it has loaded.
  44.     Do Until z_ie.READYSTATE = READYSTATE_COMPLETE
  45.         'this is an infinite loop... you may want to add a counter and escape.
  46.         'however, with a know webpage, this shouldn't usually fail.
  47.     Loop
  48.     '
  49.     'Well, lets play with the elements available on the webpage.
  50.     'by inspection of the source, it appears that the following will enter a value into the
  51.     'google search box, escape from the suggested entries, and then click on the execute
  52.     'search
  53.     With z_ie
  54.         .Visible = True
  55.         .Document.getElementById("q").Value = "VBA Example"
  56.         .Document.getElementById("q").Click
  57.         .Document.getElementById("btnK").Click
  58.     End With
  59.     '
  60.     'Now as I couldn't find a mazimize window property, I'll just use the API call
  61.     'and pass to it the handle for the current IE window.
  62.     apiShowWindow z_ie.hwnd, SW_MAXIMIZE
  63.     '
  64. errorjumpreturn:
  65.     'release
  66.     If Not z_ie Is Nothing Then Set z_ie = Nothing
  67.     '
  68. Exit Sub
  69. errorjumppoint:
  70.     'trap
  71.     MsgBox "Somethin went wrong:" & Err.Number & vbCrLf & Err.Description
  72.     Resume errorjumpreturn
  73. End Sub
I want to point out the three ".getrelementbyid" lines... you are going to have to find these yourself. by inspecting the HTML for your webpage just as I did for the Google page. Hopefully the livejournal is still up and running as this was the link that finally lead me to the developer's documentation. BTW: some of which is in German, I don't read German; however, I can muddle my way thru it and Google has a translator that works fairly well for technical material.

Respectfully, I want to make it absolutely clear that:
Bytes is neither a code writing nor homework service; however, this is such an esoteric question, IMHO, it deserves a little leeway in posting the code.
Oct 14 '13 #6
VBAToexcel
4 New Member
Hi ZMBD,

Thanks for all your help. I will go through the codes tonight. I will post the result here once again.

Thanking you once again.

With best regards.
Oct 14 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2703
by: sifar | last post by:
Hi, This is my first post to this Group. A] I am trying to create a escalation page which will mail an escalation report of a faulty product. Items needed on Page: -----------------------
0
1335
by: d3b_k | last post by:
Using Access2k with SQL2k. Form is unbound. TextBox is from an stored proc that should display a varchar field on the SQL server that can hold up to 1200. The 1200 was recently changed from 300...
6
10254
by: Thonglao Rud | last post by:
I'm trying to clear all textbox on the form. foreach (Control c in this.Controls) { //if (c.GetType() == typeof(TextBox)) if (c is TextBox) { // Found it c.Text = "";...
1
1791
by: Wes Weems | last post by:
Hello, I have a button called LoadBtn, which exists in <form name="Form1" runat=server></form> tags. I then have javascript loaded outside of that form, and apparently I cant call any methods...
0
1125
by: nail | last post by:
Hi. Think the following scenario. UC1 with a textbox control and a button control. UC2 with a textbox control and a button control too. I need to, on the click event of the button inside the...
4
507
by: Newbee | last post by:
I'm using a table (dynamically generated at runtime) for formatting wherein I have text in the first column, and textboxes in the second column. For example, (1,1) might have the string "Last Name"...
1
2007
by: simplengrichard | last post by:
Hi everyone! I need some help. I placed a webform table and then I added other controls within the cell such as dropdown box and buttons, etc. I was wondering if it is possible to access this...
3
5094
by: kimiraikkonen | last post by:
Hi experts, I just want to ask a simple procedure of my simple form. My form has a input textbox and a button. I want this if you can help me: Application user types a command prompt command...
17
3157
by: perhapscwk | last post by:
For example, i have 2 frame, one in left side and one in right side. for the right side frame, i can;t alter the code in the right frame and i just know it have a textbox id=customer then i...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.