-
Notifications
You must be signed in to change notification settings - Fork 512
Description
Serializing a form is meant to remove inputs of type submit, so that they are not sent: https://github.com//cobrateam/splinter/blob/c04a75dede7f314bba69a7ff188c147417647b12/splinter/driver/lxmldriver.py#L50-L60 (changed in https://github.com//cobrateam/splinter/commit/ad28ab4aeb56cde66a20e67cb3261324eecebeec (#611, for #595)).
However, since the change it will silently skip errors due to the element not being at the root / a direct child of the form element.
Changing the code to form_input.getparent().remove(form_input) fixes that, but has the downside of changing the form as a side-effect (i.e. serializing it twice has a different outcome).
Note that lxml provides helpers to submit a form (https://github.com/lxml/lxml/blob/50c276412880c1a3dde8a6d6c909e3ed8ef47e43/src/lxml/html/__init__.py#L1081-L1116), and getting a form's values specifically (https://github.com/lxml/lxml/blob/50c276412880c1a3dde8a6d6c909e3ed8ef47e43/src/lxml/html/__init__.py#L1011-L1041), which should be used here instead probably.
As a workaround I've used this now:
from splinter.driver.djangoclient import DjangoClient
class CustomDjangoClient(DjangoClient):
def serialize(self, form):
"""Work around https://github.com/cobrateam/splinter/issues/1059."""
return dict(form.form_values())