File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -439,7 +439,13 @@ def select(self, value):
439439 self ._control .value = value
440440
441441 def _get_parent_form (self ):
442- parent_form = next (self ._control .iterancestors ("form" ))
442+ # First, try to find the form by the `form` attribute.
443+ if 'form' in self ._control .attrib :
444+ parent_form = self ._control .getroottree ().xpath (
445+ '//*[@id="%s"][1]' % self ._control .attrib ['form' ]
446+ )[0 ]
447+ else :
448+ parent_form = next (self ._control .iterancestors ("form" ))
443449 return self .parent ._forms .setdefault (parent_form ._name (), parent_form )
444450
445451
Original file line number Diff line number Diff line change @@ -89,6 +89,13 @@ def test_clicking_submit_button_posts_button_value_if_value_present(self):
8989 "submit-button: submit-button-value" ,
9090 )
9191
92+ def test_submitting_a_form_when_the_button_is_outside_the_form (self ):
93+ self .browser .find_by_css ('input[form="form-with-submit-outside"]' ).click ()
94+ self .assertEqual (
95+ self .browser .find_by_xpath ("/descendant-or-self::*" ).text ,
96+ "submit-input: submit-input-value" ,
97+ )
98+
9299 def test_submiting_a_form_and_verifying_page_content (self ):
93100 self .browser .fill ("query" , "my name" )
94101 self .browser .find_by_name ("send" ).click ()
Original file line number Diff line number Diff line change @@ -142,6 +142,9 @@ <h1 id="firstheader">Example Last Header</h1>
142142 < input type ="text " name ="lastname ">
143143 </ form >
144144
145+ < form action ="/post " method ="POST " id ="form-with-submit-outside ">
146+ </ form >
147+ < input type ="submit " form ="form-with-submit-outside " name ="submit-input " value ="submit-input-value " />
145148
146149 < a href ="http://example.com/ "> Link for Example.com</ a >
147150 < a href ="http://example.com/last "> Link for Example.com</ a >
You can’t perform that action at this time.
0 commit comments