473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Using win32com for web automation

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','logi nrequest')"><img
src="../images/cs/en_CA/btn_ok.gif" alt="OK" border="0"></a>
<a
href="javascript:submitForm('loginForm','loginrequ estchangepassword')"><img
src="../images/cs/en_CA/btn_changepassword.gif" alt="Change Password"
border="0"></a>
<a href="javascript:submitForm('loginForm','preferenc es')"><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

Jul 26 '05 #1
5 6131
For Javascript automation, I recommend Selenium
(<http://confluence.public.thoughtworks.org/display/SEL/Home>).

Grig

Jul 26 '05 #2
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.

Jul 26 '05 #3
> 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()
Jul 26 '05 #4

ina wrote:
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

Aug 1 '05 #5
>>>>> "calfdog" == calfdog <ca*****@yahoo.com> writes:

calfdog> ina wrote:
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.


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

Aug 3 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
3
by: RJ | last post by:
Hi, I've been going over the Quick Start to Client side COM and Python and many other sources, but cannot find an example that will get my com/ActiveX .ocx USB device driver imported. The Excel...
0
by: | last post by:
Hi, A month ago, I decided to move from Delphi to Python/wxPython for a good deal of my development work, and for the past few projects (which included a full re-write of our point-of-sale system)...
0
by: mb3242 | last post by:
Hello, I'm trying to use win32com to call a method in a COM object. I'm having a problem with Python choosing the wrong type when wrapping up lists into VARIANTs. The function I'm trying to call...
8
by: Joakim Persson | last post by:
Hello all. I am involved in a project where we have a desire to improve our software testing tools, and I'm in charge of looking for solutions regarding the logging of our software (originating...
12
by: vithi | last post by:
Hi Any one tell me where I can get (or download) python modules win32com or win32com.client because I have to use "Dispatch" thanks
1
by: Girish | last post by:
Hi, I want to embed a txt document into an excel using python. Here is my code, but i get an error message =================================================== Traceback (most recent call...
1
by: captainc | last post by:
I have C++ code to import a .tlb and use a .dll that has functions that return VARIANT types and accepts BSTRs (bstrings). I have seen that python has modules that can manipulate VARIANTs and BSTRs...
11
by: Bill Davy | last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers from my address book which is an Excel spreadsheet to my mobile phone. I came across the following snippet of code which...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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
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...

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.