Using win32com for web automation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    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="JavaS cript">

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

    </SCRIPT>

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


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

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

    <a href="javascrip t:submitLoginFo rm('loginForm', 'loginrequest') "><img
    src="../images/cs/en_CA/btn_ok.gif" alt="OK" border="0"></a>
    <a
    href="javascrip t:submitForm('l oginForm','logi nrequestchangep assword')"><img
    src="../images/cs/en_CA/btn_changepassw ord.gif" alt="Change Password"
    border="0"></a>
    <a href="javascrip t:submitForm('l oginForm','pref erences')"><img
    src="../images/cs/en_CA/btn_preferences .gif" alt="Preference s"
    border="0"></a>


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

    if (focusControl.t ype != "hidden") {
    focusControl.fo cus();
    }
    // -->
    </script>
    ----------------------------------------------

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

    ie = Dispatch('Inter netExplorer.App lication')
    ie.Visible = 1
    ie.Navigate("ht tp://ispds-sepsr.prv:7500/cs/welcome.jsp")

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

    doc = ie.Document

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

    doc.loginForm.n ame.value = 'username'
    doc.loginForm.p assword.value = 'password'
    doc.loginForm.l oginform.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

  • Grig Gheorghiu

    #2
    Re: Using win32com for web automation

    For Javascript automation, I recommend Selenium
    (<http://confluence.publ ic.thoughtworks .org/display/SEL/Home>).

    Grig

    Comment

    • ina

      #3
      Re: Using win32com for web automation

      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.

      Comment

      • J Correia

        #4
        Re: Using win32com for web automation

        > from win32com.client import Dispatch[color=blue]
        > from time import sleep
        >
        > ie = Dispatch('Inter netExplorer.App lication')
        > ie.Visible = 1
        > ie.Navigate("ht tp://ispds-sepsr.prv:7500/cs/welcome.jsp")
        >
        > while ie.ReadyState != 4:
        > sleep(1)
        >
        > doc = ie.Document
        >
        > while doc.readyState != "complete":
        > sleep(1)
        >
        > doc.loginForm.n ame.value = 'username'
        > doc.loginForm.p assword.value = 'password'
        > doc.loginForm.l oginform.action = '/cs/login.do'[/color]

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

        doc.loginForm.s ubmit()


        Comment

        • calfdog@yahoo.com

          #5
          Re: Using win32com for web automation


          ina wrote:[color=blue]
          > 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.[/color]

          FYI

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

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

          # Make the browser visible
          ie.Visible = 1

          # Navigate to the site
          ie.Navigate("ht tp://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.n ame.value = 'username'

          # set the textbox value for password to 'some_string'

          doc.loginForm.p assword.value = 'password'

          # submit the form
          doc.loginForm.s ubmit()

          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



          Hope it helps
          Rob

          Comment

          • Chris Smith

            #6
            Re: Using win32com for web automation

            >>>>> "calfdog" == calfdog <calfdog@yahoo. com> writes:

            calfdog> ina wrote:[color=blue][color=green]
            >> 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.[/color][/color]

            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 OnDocumentCompl ete 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

            Comment

            Working...