Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using non-existent label for click() still submits the form (including FIX) #16

Closed
cvogt opened this issue May 12, 2010 · 3 comments
Closed

Comments

@cvogt
Copy link

cvogt commented May 12, 2010

No control with label 'asdfasdfasdf' exists. Mechanize still submits the form.

browser.forms().next().click(label='asdfasdfasdf')

The following seems to fix the issueVersion 0.2.0. In _form.py, line 3190 add to the condition:

or (label is not None)

With this fix the above clock() call raises

ControlNotFoundError: no control matching kind 'clickable', label 'asdfasdfasdf'

@cvogt
Copy link
Author

cvogt commented May 12, 2010

Workaround for people who stumble over this bug. Execute at the beginning of your code:

import mechanize
from mechanize import _request
from mechanize._form import ControlNotFoundError
def _click(self, name, type, id, label, nr, coord, return_type,
           request_class=_request.Request):
    try:
        control = self._find_control(
            name, type, "clickable", id, label, None, nr)
    except ControlNotFoundError:
        if ((name is not None) or (type is not None) or (id is not None) or
            (nr != 0) or (label is not None)): # fixed by cvogt, see http://github.com/jjlee/mechanize/issues/16
            raise
        # no clickable controls, but no control was explicitly requested,
        # so return state without clicking any control
        return self._switch_click(return_type, request_class)
    else:
        return control._click(self, coord, return_type, request_class)
mechanize._form.HTMLForm._click = _click

@jjlee
Copy link
Owner

jjlee commented May 13, 2010

Fix failure to raise on click for nonexistent label

Closed by 28b77f5

@cvogt
Copy link
Author

cvogt commented May 13, 2010

that was quick, thanks so much!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants