jjlee / mechanize

Stateful programmatic web browsing in Python, after Andy Lester's Perl module WWW::Mechanize .
http://wwwsearch.sourceforge.net/mechanize/
618 stars 123 forks source link

No way to pass arbitrary predicate to .click / .submit methods #20

Open jjlee opened 14 years ago

jjlee commented 14 years ago

This should result in the first button being clicked:

import mechanize
browser = mechanize.Browser()
browser.set_response(mechanize.make_response(
        """\
<button type="submit" name="action" value="publish">Publish</button>
<button type="submit" name="action" value="preview">Preview</button>
""",
        [("Content-Type", "text/html")],
        "http://example.com/", 200, "OK"))
form = browser.global_form()
form.click(predicate=lambda control: control.name == "publish")