Fixed bug FormRequest.from_response() clickdata ignores input[type=image]

This commit is contained in:
Viral Mehta 2018-03-03 18:17:49 +05:30
parent acd2b8d43b
commit d5b7ebcfdc
2 changed files with 16 additions and 4 deletions

View File

@ -170,10 +170,12 @@ def _get_clickable(clickdata, form):
"""
clickables = [
el for el in form.xpath(
'descendant::*[(self::input or self::button)'
' and re:test(@type, "^submit$", "i")]'
'|descendant::button[not(@type)]',
namespaces={"re": "http://exslt.org/regular-expressions"})
'descendant::*[(self::input or self::button)'
' and re:test(@type, "^submit$", "i")]'
'|descendant::*[(self::input or self::button)'
' and re:test(@type, "^image$", "i")]'
'|descendant::button[not(@type)]',
namespaces={"re": "http://exslt.org/regular-expressions"})
]
if not clickables:
return

View File

@ -532,6 +532,16 @@ class FormRequestTest(RequestTest):
req = self.request_class.from_response(response, dont_click=True)
fs = _qs(req)
self.assertEqual(fs, {b'i1': [b'i1v']})
def test_from_response_clickdata_does_not_ignore_image(self):
response = _buildresponse(
"""<form>
<input type="text" name="i1" value="i1v">
<input id="image" name="i2" type="image" value="i2v" alt="Login" src="http://my.image.org/1.jpg">
</form>""")
req = self.request_class.from_response(response, dont_click=True)
fs = _qs(req)
self.assertEqual(fs, {b'i1': [b'i1v'], b'i2': [b'i2v']})
def test_from_response_dont_submit_reset_as_input(self):
response = _buildresponse(