This repository was archived by the owner on Mar 4, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +36
-7
lines changed Expand file tree Collapse file tree 4 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -218,12 +218,17 @@ protected function getRelatedElements($value = null)
218218 }
219219 }
220220
221- return $ this ->element ->findElements (WebDriverBy::xpath (sprintf (
222- '//form[@id = %1$s]//input[@name = %2$s%3$s] | //input[@form = %1$s and @name = %2$s%3$s] ' ,
223- XPathEscaper::escapeQuotes ($ formId ),
224- XPathEscaper::escapeQuotes ($ this ->name ),
225- $ valueSelector
226- )));
221+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#form
222+ return $ this ->element ->findElements (
223+ WebDriverBy::xpath (sprintf (
224+ '//form[@id = %1$s]//input[@name = %2$s%3$s '
225+ . ' and ((boolean(@form) = true() and @form = %1$s) or boolean(@form) = false())] '
226+ . ' | //input[@form = %1$s and @name = %2$s%3$s] ' ,
227+ XPathEscaper::escapeQuotes ($ formId ),
228+ XPathEscaper::escapeQuotes ($ this ->name ),
229+ $ valueSelector
230+ ))
231+ );
227232 }
228233
229234 /**
Original file line number Diff line number Diff line change @@ -51,6 +51,12 @@ public function testGetFirstSelectedOption()
5151 $ this ->assertSame ('j2a ' , $ c ->getFirstSelectedOption ()->getAttribute ('value ' ));
5252 }
5353
54+ public function testGetFirstSelectedOptionWithSameNameDifferentForm ()
55+ {
56+ $ radio = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@id="j5b"] ' )));
57+ $ this ->assertEquals ('j5b ' , $ radio ->getFirstSelectedOption ()->getAttribute ('value ' ));
58+ }
59+
5460 public function testSelectByValue ()
5561 {
5662 $ selectedOptions = ['j2b ' , 'j2c ' ];
Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ public function testGetFirstSelectedOption()
5555 $ this ->assertSame ('j3a ' , $ c ->getFirstSelectedOption ()->getAttribute ('value ' ));
5656 }
5757
58+ public function testGetFirstSelectedOptionWithSameNameDifferentForm ()
59+ {
60+ $ radio = new WebDriverRadios ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@id="j4b"] ' )));
61+ $ this ->assertEquals ('j4b ' , $ radio ->getFirstSelectedOption ()->getAttribute ('value ' ));
62+ }
63+
5864 public function testSelectByValue ()
5965 {
6066 $ c = new WebDriverRadios ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="radio"] ' )));
Original file line number Diff line number Diff line change 2727 < input type ="radio " name ="j3 " value ="j3b ">
2828 </ label >
2929
30+ < label for ="j4a "> J4A</ label >
31+ < input type ="radio " form ="yet-another-form " name ="j4 " value ="j4a " id ="j4a " checked />
32+
33+ < label for ="j5a "> J5A</ label >
34+ < input type ="checkbox " form ="yet-another-form " name ="j5 " value ="j5a " id ="j5a " checked />
35+
3036 < input type ="submit " value ="OK ">
3137</ form >
3238
3642< label for ="j3c "> J3C</ label >
3743< input type ="radio " form ="another-form " name ="j3 " value ="j3c " id ="j3c ">
3844
39- < form >
45+ < label for ="j4b "> J4B</ label >
46+ < input type ="radio " form ="another-form " name ="j4 " value ="j4b " id ="j4b " checked >
47+
48+ < label for ="j5b "> J5B</ label >
49+ < input type ="checkbox " form ="another-form " name ="j5 " value ="j5b " id ="j5b " checked >
50+
51+ < form id ="yet-another-form ">
4052 < input type ="checkbox " name ="single-cb ">
4153</ form >
4254</ body >
You can’t perform that action at this time.
0 commit comments