diff --git a/splinter/driver/lxmldriver.py b/splinter/driver/lxmldriver.py index 66ed18668..7f1ca478b 100644 --- a/splinter/driver/lxmldriver.py +++ b/splinter/driver/lxmldriver.py @@ -453,7 +453,13 @@ def select(self, value): self._control.value = value def _get_parent_form(self): - parent_form = next(self._control.iterancestors("form")) + # First, try to find the form by the `form` attribute. + if 'form' in self._control.attrib: + parent_form = self._control.getroottree().xpath( + '//*[@id="%s"][1]' % self._control.attrib['form'] + )[0] + else: + parent_form = next(self._control.iterancestors("form")) return self.parent._forms.setdefault(parent_form._name(), parent_form) diff --git a/tests/form_elements.py b/tests/form_elements.py index 16e0280b7..0cce9e565 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -98,6 +98,14 @@ def test_clicking_submit_button_posts_button_value_if_value_present(self): "submit-button: submit-button-value", ) + def test_submitting_a_form_when_input_is_outside_the_form(self): + self.browser.find_by_css('input[form="form-with-submit-outside"]').click() + assert "submit-input: submit-input-value" == self.browser.find_by_xpath("/descendant-or-self::*").text + + def test_submitting_a_form_when_button_is_outside_the_form(self): + self.browser.find_by_css('button[form="form-with-submit-outside"]').click() + assert "submit-button: submit-button-value" == self.browser.find_by_xpath("/descendant-or-self::*").text + def test_submiting_a_form_and_verifying_page_content(self): self.browser.fill("query", "my name") self.browser.find_by_name("send").click() diff --git a/tests/static/index.html b/tests/static/index.html index aaa0259b9..744ef50bd 100644 --- a/tests/static/index.html +++ b/tests/static/index.html @@ -154,6 +154,11 @@