Allow button cotrols to submit form

This commit is contained in:
Olaf Dietsche 2015-07-11 16:11:31 +02:00
parent e5f26078fa
commit 121d7535be
1 changed files with 6 additions and 4 deletions

View File

@ -150,14 +150,16 @@ def _get_clickable(clickdata, form):
if the latter is given. If not, it returns the first
clickable element found
"""
clickables = [el for el in form.xpath('.//input[@type="submit"]')]
clickables = [el for el in form.xpath('descendant::input[@type="submit"]'
'|descendant::button[@type="submit"]'
'|descendant::button[not(@type)]')]
if not clickables:
return
# If we don't have clickdata, we just use the first clickable element
if clickdata is None:
el = clickables[0]
return (el.name, el.value)
return (el.get('name'), el.get('value'))
# If clickdata is given, we compare it to the clickable elements to find a
# match. We first look to see if the number is specified in clickdata,
@ -169,7 +171,7 @@ def _get_clickable(clickdata, form):
except IndexError:
pass
else:
return (el.name, el.value)
return (el.get('name'), el.get('value'))
# We didn't find it, so now we build an XPath expression out of the other
# arguments, because they can be used as such
@ -177,7 +179,7 @@ def _get_clickable(clickdata, form):
u''.join(u'[@%s="%s"]' % c for c in six.iteritems(clickdata))
el = form.xpath(xpath)
if len(el) == 1:
return (el[0].name, el[0].value)
return (el[0].get('name'), el[0].get('value'))
elif len(el) > 1:
raise ValueError("Multiple elements found (%r) matching the criteria "
"in clickdata: %r" % (el, clickdata))