Skip to content

Submitting a form send inputs of type submit that were not clicked #1059

@blueyed

Description

@blueyed

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())

Metadata

Metadata

Assignees

No one assigned

    Labels

    djangoRelates to the Django client

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions