Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
blueyed opened this issue Jun 22, 2022 · 0 comments
Open

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

blueyed opened this issue Jun 22, 2022 · 0 comments
Labels
django Relates to the Django client

Comments

@blueyed
Copy link
Contributor

blueyed commented Jun 22, 2022

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())
@jsfehler jsfehler added the django Relates to the Django client label Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
django Relates to the Django client
Projects
None yet
Development

No branches or pull requests

2 participants