Solved

IE developer tool "gathering textbox names" from a web page/

Posted on 2014-02-15
12
829 Views
Last Modified: 2014-02-20
I want to automate a program for entering data to a government web page.

The web page has about two dozen textboxs, each of which as an element name.

Here is how I currently do this with my dual monitor setup.
1 I open notepad on screen 2
and  open ie webpage on screen 1
2 f12 to developer tool and move it to screen 2
3 screen 2 > find > select element by click.
4 in ie click on textbox #1
5 on screen 2, the html for textbox #1 is automatically highlighted.  I right click > copy
6 I paste it into notepad.

I repeat steps 3 to 6 for all the text boxes.

This is a little cumbersome.  Is there anything like the Excel Recorder, that can be used to automatically gather the field names, so I can just click from one field to another and have the text automatically be put to the clipboard, or similar scratch area?

rberke
0
Comment
Question by:rberke
  • 7
  • 5
12 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
Does your browser support auto form fill?
0
 
LVL 5

Author Comment

by:rberke
Comment Utility
I am using IE 10, and yes it does support auto form fill. But, the data is dynamic, so I plan on using vba to fill in to web page
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
If you just find the form tag in you can copy that then past the to your note pad.  From there you can easily see the input tags and grab what you need.

This does not seem to work well using IE because when you paste, the formatting did not keep the  line breaks.  When I do this in chrome, you can see the same line breaks and it is much easier to read.

On a side, note, if you are posting to a website from outside the site, make sure it is within the terms of service.
0
 
LVL 5

Author Comment

by:rberke
Comment Utility
You suggested <<If you just find the form tag in you can copy that then past the to your note pad.  From there you can easily see the input tags and grab what you need.>>

I am already doing exactly what you suggest. In fact, that is exactly what I outlined in my original post.

I was looking for an easier way.  Instead of two dozen cut and paste operations I want something that would put the key-able text boxes clipboard.
0
 
LVL 5

Author Comment

by:rberke
Comment Utility
I wrote a vba routine to do what I wanted. Using this routine, I generated code for 2 dozen txt fields in 1 minute !!!!

But, if a rookie web developer like me can do this in a few hours, there has GOT TO BE a nifty tool that will do it for me in a much better manner.

Experts-Exchange MUST have a web developer expert that has seen something like this.

I am keeping this post open in the hopes that some guru can point me to such a tool. If nobody can help, I will PAQ it with my own answer.

rberke

Sub IEMTC()
' ieMtc = make textbox code
'   creates code for current text box, then advances to next textbox.
'
' keyin the values you want in the text boxes then position cursor to first text box.
' run IeMtc
'   it will put .document.getelementbyname("xxxxx")(0).value = "xyz"

Dim objie, code


Set objie = waitThenGetobject("InternetExplorer.Application")

With objie
code = ".Document.getElementsByName('aaaaa')(0).Value = 'vvvvv'"
code = Replace(code, "aaaaa", .Document.activeElement.name)
code = Replace(code, "vvvvv", .Document.activeElement.Value)
code = Replace(code, "'", chr$(34))
Debug.Print code
AppActivate "Windows Internet Explorer"
Sleep 100
SendKeys "{TAB}"
        AppActivate Application ' <== only needed if I am using vba IDE to test the code.
End With


End Sub
Function waitThenGetobject(objectclass As String) As Object ' this routine is useful because getobject("Internetexplorer.application") gives Error Number: 429" "ActiveX component can't create object or return object
' this returns the first object of the desired type
' only tested with internetexplorer.application
If LCase(objectclass) <> "internetexplorer.application" _
And LCase(objectclass) <> "x.y" Then Error 1
    Dim shellWins As SHDocVw.ShellWindows
    Dim explorer As SHDocVw.InternetExplorer
    Set shellWins = New SHDocVw.ShellWindows
  
        On Error Resume Next ' avoid problem: sometimes this code threw -2147417848  The object invoked has disconnected from its clients.
        For Each explorer In shellWins
            If Not explorer Is Nothing Then
                Dim fullname As String
                fullname = ""
                fullname = explorer.fullname
                If InStr(1, fullname, "iexplore.exe", 1) > 0 Then
                    Set waitThenGetobject = explorer
                End If
            End If
        Next
End Function

Open in new window

0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
Comment Utility
I started on this and was sidetracked.   If you just want to get the name value it would be faster to do the parsing in the browser with javascript.  

In the sample below you can paste in all the form data and tab out and you will get both a comma delimited list of field names and a vertical list.  

I guess don't understand the need for all your original steps.  All you should need to do is right click about where the form is, view the dev tool, find the <form> tag, right click on that and copy. That will save all the html.  

Now paste that into your text box, tab out of the box and you will see the data.

http://jsbin.com/zuwacuqi/1/
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
  <script>
    $( document ).ready(function() {
$('textarea').focusout(function () {

    var $data = $(this).val();
    $('#temp').html($data);

    getHtml();

});

function getHtml() {
    var xHtml = '';
    var myArray = [];
    $('#temp input').each(function () {
        var name = $(this).attr('name');
        myArray.push(name);
    });
    $('#temp').hide();
    $('#results1').text(myArray);
    for (var i = 0; i < myArray.length; i++) {
        xHtml = xHtml + myArray[i] + '<br>';
    }
    $('#results2').html(xHtml);
}
});
    </script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <textarea cols="70" rows="10"></textarea>
  <div id="temp"></div>
  <p>Input Names Parsed</p>
  <div id="results1"></div>
  <hr>
  <div id="results2"></div>

  
</body>
</html>

Open in new window


If you wanted to get extra fancy, you can use xmlhttp server side with a get, grab the html and place it to the text box.  

In vbscript that looks something like
<%
url ="http://somesite.com/page"
	
	
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") 
    xmlhttp.open "GET", url, false 
    xmlhttp.send "" 
    theHtml= xmlhttp.responseText
' now place theHtml in the textarea
%>
<textarea><%=theHtml%></textarea>

Open in new window

Since all of that will load on the server/localhost before the actual html is rendered, you can just change the js line
('textarea').focusout(function () {

Open in new window

to
('textarea').ready(function () {

Open in new window


Even fancier, instead of hard coding the url, you may want to create a form on that page to accept a url as input.  In that case change

url ="http://somesite.com/page"

Open in new window

to
url =<%=request("myURLinput")%>

Open in new window


If you have not noticed, my serverside code is asp classic vbs.  You can just as easily do this in .net or php

Best of luck.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Author Comment

by:rberke
Comment Utility
After 10 years of programming vba, I am pretty good at it, but I know nothing about Java Script, or xmlhttp.

I tried copying your script into a MyProg.js file, but I just guessed at the extension, and it got nowhere.

I clicked on your hyperlink, which executed fine, but when I pasted HTML into the text box nothing happened.

And, I copied your vbscript into a myprog.vbs file, changed the URL and of course, it didn't compile because the <% isn't really vbscript.  

3 strikes so far, and I feel like I am really out.

I admit am in way over my head and should take a class on all this junk.  

If you have time, I hope you can give me a few pointers, but I realize I have way too much too learn, so I should probably just close this question.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
<% is typically asp classic and that is what I used but it is vbscript not vba.  Well, a mix of asp and vbs.

The way you should start is by simply taking the original html code I gave you here http:Q_28365799.html#a39868961, copy all of it, paste it to your text editor, then save it as a .html file.   So we are talking the same thing, save it as test.html

Now you can open test.html with your browser and you shouldn't even have to do it using localhost at this point.  It should look and act identical to the jsbin link I gave you.  You will have to have an internet connection as I am referencing the jquery cdn.

Can you get that working?

Do you have localhost running?  can you run php or asp?
0
 
LVL 5

Author Comment

by:rberke
Comment Utility
I saved it as Myprog.html and it runs just like the jsbin.

Don't know how to tell if local host/php/asp is running.

When I look for files ending in php, I see the extension is associated with microsoft expression Web version 4.0 free version (which I installed recently and never used.)
0
 
LVL 5

Author Comment

by:rberke
Comment Utility
I made some progress.  

How can I modify your wonderful application, so that I can simply paste the ENTIRE tgt.htm. webpage.

Here are a few details.

 I changed my target.html to target.txt, and opened it in notepad.

If I grab specific chunks of my tgt.txt and paste it into your JS Bin text window, it does a GREAT job of parsing dozens of text boxes.

But, when I use ctrl A  to grab all of tgt.txt and paste it into JS Bin, NOTHING happens.

I played a little, and grabbed most of tgt.txt  from <html> to ></html>.

When I paste that into your window, it renders the entire webpage, but didn't parse any text box names.

I then randomly dropped a dozen lines from the top and bottom of tgt.txt and pasted that into JS Bin. Voila, it produced a COMPLETE list.

So how can I modify your wonderful application, so that I can simply paste the ENTIRE tgt.htm. webpage?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
We just need to filter for the input. I have updated the js portion below and this is the new working sample.  http://jsbin.com/padasQ_28365799/3/edit?html,output

$( document ).ready(function() {
      
$('textarea').focusout(function () {
    var formData = $(this).val();
     formData=$(formData).filter(':input'); 
    $('#temp').html(formData);

    getHtml();

});

function getHtml() {
    var xHtml = '';
    var myArray = [];
    $('#temp input').each(function () {
        var name = $(this).attr('name');
        myArray.push(name);
    });
    $('#temp').hide();
    $('#results1').text(myArray);
    for (var i = 0; i < myArray.length; i++) {
        xHtml = xHtml + myArray[i] + '<br>';
    }
    $('#results2').html(xHtml);
}
});

Open in new window

0
 
LVL 5

Author Comment

by:rberke
Comment Utility
Well, it still does nothing when I paste the entire contents of the html file.


But, it probably isn't worth pursing right now, I have already used the output from my previous step, and am on to other tasks now.

When I have more time, I may repost and see if we can get it to work better.

I will close the problem with thanks for your help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now