Hi,

I need to login to a site, make some changes and then there is an apply button which i need to click to save the changes. The HTML code is as below for the buttons <input type="button" onclick="clickApply()" alt="Apply" value="Apply " class="button" name="applybutton" id="postApply"/> I am able to login and make the changes but not able to save it..

Heres the code i tried :

import mechanize
br = mechanize.Browser()
br.add_password("http://blah.blah/", "adm", "mps")
response = br.open("http://blah.blah/blah2.html")
br.select_form(nr=1)
br["junk"]=["hatethis"]
response3=br.form.click(name="applybutton",nr=1)

This is the response i get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/ClientForm.py", line 3095, in click
    self._request_class)
  File "/usr/lib/python2.6/dist-packages/ClientForm.py", line 3294, in _click
    name, type, "clickable", id, label, None, nr)
  File "/usr/lib/python2.6/dist-packages/ClientForm.py", line 3287, in _find_control
    raise ControlNotFoundError("no control matching "+description)
ClientForm.ControlNotFoundError: no control matching name 'applybutton', kind 'clickable', nr 1

I tried br.submit() and br.click() but nothing works..


I read the site http://wwwsearch.sourceforge.net/ClientForm/

which said :

Why does .click()ing on a button not work for me?

* Clicking on a RESET button doesn't do anything, by design - this is a library for web automation, not an interactive browser. Even in an interactive browser, clicking on RESET sends nothing to the server, so there is little point in having .click() do anything special here.
* Clicking on a BUTTON TYPE=BUTTON doesn't do anything either, also by design. This time, the reason is that that BUTTON is only in the HTML standard so that one can attach callbacks to its events. The callbacks are functions in SCRIPT elements (such as Javascript) embedded in the HTML, and their execution may result in information getting sent back to the server. ClientForm, however, knows nothing about these callbacks, so it can't do anything useful with a click on a BUTTON whose type is BUTTON.


So is there anyway 2 do it??

br.form.action="clickApply()"

This did not work :( I dont think mechanize can handle javascript. I am going to give selenium RC a try..

response3=br.form.submit(name="applybutton",nr=0)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.