Send data to webpage

Windows 8.1 comes with 11.09 which does not show the title either. But using the task manager, it shows the title of the window that is not displayed. The Sendkeys works with that title. I looked at a way to list the currently running windows the way Tak Manager does, and found http://stackoverflow.com/questions/5951631/how-to-get-captions-of-actual-windows-currently-running which is in Delphi.

I have tried to simply enter a query into the Google page. First, the query field does not have the focus, then it is something like 8th in the tab order, if the windows has just open. And if no popup thingy wants to tell you something like “have I got an update for superplug”…

Indeed automating windows with sendkeys seems a shaky business. Maybe the other PW managers are using other means ?

Address the field in the page by looking at the HTML DOM

I have an app, albeit a Mac app, that can populate a value to a web page. I use Javascript, sent by AppleScript.

In Javascript you can use document.getElementById(xxxxx) to find a particular ID. All mine are static so I just use document.forms[‘inputForm’][‘username’].value = ‘username’ for example

Can you accomplish this in Windows by sending Javascript from your app?

On a side note, AppleScript can address a particular window

tell application Safari
set doc to front document
do JavaScript “document.forms[‘inputForm’][‘password’].value = ‘password’ in doc”
end tell

tell application Safari
set doc to document “Bletchley Park - Login Window”
do JavaScript “document.forms[‘inputForm’][‘password’].value = ‘password’ in doc”
end tell

Dave, I know it has been a while and you may have moved on since, but I just found an interesting way of addressing a particular running program under Windows in a manner close to what is done in AppleScript by "Tell "

The command line Tasklist /v provides a list of all running processes by their program file name, and window title.

So for instance you could have iexplore.exe and window title mySite - Internet Explorer. It then becomes possible to Sendkeys the password to the window title, followed by {RETURN}.

I could not find ways of sending JavaScript to Internet Explorer, but it is possible in Xojo HTMLViewer through ExecuteJavascript.

Thanks… I will look into that…

DaveA… problem is I have no idea what the fields are named…my app would just blindly assume the first two fields on the page…

I believe most password managers rely on the fact that web developers name these fields consistently: “Username” and “Password”. Otherwise, how would any such manager know what data to save and where to stick it back in?

[quote=90947:@Dave S]problem is I have no idea what the fields are named…my app would just blindly assume the first two fields on the page.
[/quote]

I am working on web automation myself. The way I find out about the field names is by going to the site, view page source and spot the fields names. Then I believe it becomes necessary to provide a sort of shortcut for every targeted site, where are stored URL and field names. This would work fine for Mac.

For Windows and Internet Explorer, automation being limited to keyboard, I usually visit the site and see if I can pilot the navigation by the keyboard. This is somewhat limited, though.

For an HTML page, I know how to download the page, get the URL of the Form Action, and POST the field data. To send a new URL through IE, I sendkey {Tab} then the URL, then {RETURN}

The problem with automation is that it is somewhat limited. It is much easier to work through an HTMLViewer and use ExecuteJavaScript.

Your assumption does not do justice to developers imagination, Tim :wink:

As a matter of fact, I found out that there is almost no two pages with the same field names. Hence the need to have a database where for a given site the field names are stored.

Dave’s approach by the two first fields may work often, as JavaScript allows to address fields by their order, but it will not be reliable.

This does not seem to work :frowning:

You probably already did this, but you may need to adjust the quotes

Ie.,

HTMLViewer1.ExecuteJavascript("document.forms['inputForm']['password'].value = '"+thePassword+"';")

[quote=90972:@Tim Hare]You probably already did this, but you may need to adjust the quotes

Ie.,

HTMLViewer1.ExecuteJavascript("document.forms['inputForm']['password'].value = '"+thePassword+"';")
[/code][/quote]

No luck either. I can click buttons fine, I can click fields to give them focus fine but any time and any method I try to set the value of a field with HTMLViewer.ExecuteJavaScript simply does not work. I read on the Internet that it does not work because it would break JavaScript security rules to modify a field from another domain than the site. Yet there are countless posts showing that method.

It seems a lot of posters simply copy the manual and do not take into account that what works on a server may not work on the client browser DOM.

It is not a major issue, as after having set the focus on a field, I can send keystrokes into it. Using Sendkeys in Windows, and on Mac :

[code]tell application "Safari"
	activate
	open location "https://duckduckgo.com/"
	delay 3
	activate
	do JavaScript "document.getElementByName('search_form_input_homepage').click();"
	tell application "System Events" to keystroke "this is the data I want to have typed"
	tell application "System Events" to keystroke (ASCII character 13)
	
end tell

Dave, your ‘two first fields’ technique won’t work on the Gravatar site.

The welcome page presents simply a Sign In button that one has to click to get to the actual login page. Chrome clicks on it by entering 9 tabs followed by {Return}.

Internet Explorer needs 13 tabs.

It means a password manager using automation would have to stick to Internet Explorer to make sure the script works, or address differences between browsers.

The structure of sites varies greatly as well. The Bank of America site, for instance, sets focus on the username field. After entering the username, one must go {Return} and then be presented with the password.

All that makes me think that on Windows, a way to log in properly on all sites could be bookmarks with the following information :

  • URL
  • Delay
  • Keys to send in the user field
  • Delay
  • Keys to send in the password field

On Mac seems like each site could benefit from its own script.