Using win32com for web automation

C

Chris

Hi,

I'm trying to figure out how to submit javascript forms using win32com
in order to complete repetitive processes.

The Webpage Source: (I tried to include only the important stuff)
----------------------------------------------
<SCRIPT language="JavaScript">

function mainPageOnLoad() {
initLogin();
setEnterToSubmit('loginForm','loginrequest');
}

</SCRIPT>

<form name="loginForm" method="post" action="/cs/login.do">
<input type="hidden" name="nxtpage" value="">
<input type="hidden" name="currentpage" value="login">
<input type="hidden" name="lng" value="en_CA">


<td width="38%" align="right" valign="middle" height="25"
class="detailslabel">
Name:&nbsp</td>
<td width="62%" class="detailsvalue">
<input type="text" name="name" maxlength="15" size="15"
value="">

<td width="38%" align="right" valign="middle" height="25"
class="detailslabel">
Password:&nbsp</td>
<td width="62%" align="left" valign="middle" height="25"
class="detailsvalue">
<input type="password" name="password" maxlength="15" size="15"
value="">

<a href="javascript:submitLoginForm('loginForm','loginrequest')"><img
src="../images/cs/en_CA/btn_ok.gif" alt="OK" border="0"></a>
<a
href="javascript:submitForm('loginForm','loginrequestchangepassword')"><img
src="../images/cs/en_CA/btn_changepassword.gif" alt="Change Password"
border="0"></a>
<a href="javascript:submitForm('loginForm','preferences')"><img
src="../images/cs/en_CA/btn_preferences.gif" alt="Preferences"
border="0"></a>


<script type="text/javascript" language="JavaScript">
<!--
var focusControl = document.forms["loginForm"].elements["name"];

if (focusControl.type != "hidden") {
focusControl.focus();
}
// -->
</script>
----------------------------------------------

My code so far is this:
----------------------------------------------
from win32com.client import Dispatch
from time import sleep

ie = Dispatch('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate("http://ispds-sepsr.prv:7500/cs/welcome.jsp")

while ie.ReadyState != 4:
sleep(1)

doc = ie.Document

while doc.readyState != "complete":
sleep(1)

doc.loginForm.name.value = 'username'
doc.loginForm.password.value = 'password'
doc.loginForm.loginform.action = '/cs/login.do'
-------------------------------------------------

Well it doesn't seem to work like other javascript sites (eg. like the
google.ca form)which is where i snagged the script from.
I don't really have a clue about this module, or even javascript so any
help would be appreciated.

P.S. sorry about the mess
 
I

ina

Look up pamie it should do all the work you need. If it dosn't I can
send you ishyBrowser but pamie has more comunity support.
 
J

J Correia

from win32com.client import Dispatch
from time import sleep

ie = Dispatch('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate("http://ispds-sepsr.prv:7500/cs/welcome.jsp")

while ie.ReadyState != 4:
sleep(1)

doc = ie.Document

while doc.readyState != "complete":
sleep(1)

doc.loginForm.name.value = 'username'
doc.loginForm.password.value = 'password'
doc.loginForm.loginform.action = '/cs/login.do'

I can't get to that site to test.
Try the following instead of the last line above:

doc.loginForm.submit()
 
C

calfdog

ina said:
Look up pamie it should do all the work you need. If it dosn't I can
send you ishyBrowser but pamie has more comunity support.

FYI

#Imports
from win32com.client import Dispatch
from time import sleep

# Create a new browser object
ie = Dispatch('InternetExplorer.App­lication')

# Make the browser visible
ie.Visible = 1

# Navigate to the site
ie.Navigate("http://ispds-sepsr.prv:7500/cs/welcome.jsp")


# wait for the document to fully load
while ie.ReadyState != 4:
sleep(1)

doc = ie.Document

while doc.readyState != "complete":
sleep(1)


# set the textbox value for name to 'some_string'
doc.loginForm.name.value = 'username'

# set the textbox value for password to 'some_string'

doc.loginForm.password.value = 'password'

# submit the form
doc.loginForm.submit()

Added some comments to make it clearer

You will now need another wait for the next document you load
You can put the wait into a wait method

or you could try PAMIE
http://pamie.sourceforge.net


Hope it helps
Rob
 
C

Chris Smith

calfdog> # wait for the document to fully load
calfdog> while ie.ReadyState
calfdog> != 4: sleep(1)
calfdog> doc = ie.Document
calfdog> while doc.readyState != "complete": sleep(1)

I was trying to make this work several months ago, and tried
to open the windows event to trap the OnDocumentComplete from IE.
It was all beat.
I went with the über-hack: a sentinel file in a certain spot writing
the word 'Done'.
COM programming recalls the Steven Write joke: "Went to the hardware
store to buy some batteries, but they weren't included; so I had to
buy them again."
Grr,
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top