Skip to content

Commit

Permalink
Fix #253 multiple dropdowns on the same page with same values
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Mar 27, 2016
1 parent de41b3b commit 5bfc001
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/files/testpages/selectOptions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<body>

<select id="test-select">
<option value="r">Red</option>
<option value="g">Green</option>
<option value="b">Blue</option>
</select>
<br />
<select id="test-select2">
<option value="r">Red</option>
<option value="g">Green</option>
<option value="b">Blue</option>
</select>

</body>
</html>
4 changes: 2 additions & 2 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ let last cssSelector = (List.rev (elements cssSelector)).Head
let private writeToSelect (elem:IWebElement) (text:string) =
let options =
if writeToSelectWithOptionValue then
unreliableElementsWithin (sprintf """//option[text()="%s"] | //option[@value="%s"]""" text text) elem
unreliableElementsWithin (sprintf """option[text()="%s"] | option[@value="%s"] | optgroup/option[text()="%s"] | optgroup/option[@value="%s"]""" text text text text) elem
else //to preserve previous behaviour
unreliableElementsWithin (sprintf """//option[text()="%s"]""" text) elem
unreliableElementsWithin (sprintf """option[text()="%s"] | optgroup/option[text()="%s"]""" text text) elem

match options with
| [] -> raise (CanopyOptionNotFoundException(sprintf "element %s does not contain value %s" (elem.ToString()) text))
Expand Down
7 changes: 7 additions & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ context "other tests"
"#states" << "95"
"#states" == "Palmyra Atoll"

"writting (selecting) to drop down test, two selects same value" &&& fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/selectOptions"
"#test-select" << "g"
"#test-select2" << "b"
"#test-select" == "Green"
"#test-select2" == "Blue"

"writting (selecting) to drop down test, value list, opt group" &&& fun _ ->
!^ testpage
"#test-select" << "Audi"
Expand Down

0 comments on commit 5bfc001

Please sign in to comment.