Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:20:07+00:00 2026-06-02T02:20:07+00:00

I m trying to automate logging into a website using Python’s mechanize module.Following is

  • 0

I m trying to automate logging into a website using Python’s mechanize module.Following is the login form code:

    <TD><B>Site:</B></TD>
    <TD><SELECT name="site" class="drpdwn" size=1 width="200" onChange="populateZones(this, '');"><OPTION value="">Select a site</OPTION></SELECT>
    <INPUT type="hidden" name="shortsite" size="3" value=""></TD>
</TR>
<TR>
    <TD><B>Zone:</B></TD>
    <TD><SELECT name="zone" class="drpdwn" size=1 width="100"><OPTION value="">Select a zone</OPTION></SELECT></TD>
</TR>
<TR>
    <TD><B>User ID:</B></TD>
    <TD><INPUT type="text" name="user" size=20 value=""></TD>
</TR>
<TR>
    <TD><B>Password:</B></TD>
    <TD><INPUT type="password" name="password" size=20></TD>
</TR>
<TR>
    <TD>&nbsp;</TD>
    <TD><INPUT name="submit1" type="submit" value="Log On" style="color: #003399; font-weight: bold; font-size: 10pt">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="reset1" type="reset" value="Reset" style="color: #003399; font-weight: bold; font-size: 10pt" onClick="resetform();">
    </TD>

I m able to parse and populate user, password and shortsite fields without any difficulty. The problem comes in while populating the zone drop down list. As is evident from the HTML code above that the webpage is using populateZones javascript function to populate the zones. I m looking for a way to force the zone value as stored in the configuration file. I have done similar things in the past using HTML::Form::ForceValue.Is there any equivalent in python?

Below is an excerpt from the python script that i m working on to automate the login:

br['user'] = self.config['COMMON.USER']
br['password'] = self.config['COMMON.PASSWORD']

if 'COMMON.SITE' in self.config and 'COMMON.ZONE' in self.config:
try:
br.form.set_all_readonly(False)
br.form["shortsite"] = self.config['COMMON.SITE']
br.form.find_control(name="zone").set_value_by_label([self.config['COMMON.ZONE']])
except ControlNotFoundError, err:
logger = logging.getLogger(__name__)
logger.info(str(err))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:20:09+00:00Added an answer on June 2, 2026 at 2:20 am

    I was able to get this going by emmulating the javascript. Sharing the code as might be of some help:

    br.select_form(predicate=self.__form_with_fields("user", "password"))  
    br.form.set_all_readonly(False)  
    br['user']           = self.config['COMMON.USER']  
    br['password']       = self.config['COMMON.PASSWORD']  
    br.form["shortsite"] = self.config['COMMON.SITE'] 
    
    zone1 = br.form.find_control("zone")
    
    #Add drop down list value dynamically like the Javascript does
    mechanize.Item(zone1, {"contents": "Hurray","value": "Hurray"})
    
    #Choose the just added option
    br.form["zone"] = ["Hurray"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying automate a login process to my web application using Selenium-Python Client
I'm trying to find a way to automate some exception logging code to add
I am trying to automate some Weka classification using Java code. I'm getting the
I am trying to automate logging into Photobucket for API use for a project
I'm trying to automate a gdb session using the --command flag. I'm trying to
I am trying to automate functional testing of a server using a realistic frequency
I am trying to automate data extraction from a website and I really don't
I'm trying to automate the build of a project in Delphi 2009. I'm using
Am trying to automate the process of uploading an artifact generated by Maven into
I am trying to automate the set up of site creation for our in-house

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.