cobrateam / cobrateam/splinter

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

Open
#1,059 3 comments 0 reactions 0 assignees View on GitHub
django
Dominant language
Python
Stars
2.7k
Forks
511
PR merge metrics
No merged PRs in 30d

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:
```python
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())
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.