Skip to content

Commit

Permalink
Fix for #240, selects with optgroups not working
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Mar 12, 2016
1 parent 80d31c8 commit 47d8cad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 13 additions & 0 deletions docs/files/testpages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ <h1 id="welcome">Welcome</h1>
<br>
<label>I've got an apostrophe</label>

<br>
<br>
<select id="test-select">
<optgroup label="Swedish Cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
</optgroup>
<optgroup label="German Cars">
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>

<script type="text/javascript">
$(document).ready(function () {
setTimeout(function () { $("#ajax").html("ajax loaded"); }, 2000)
Expand Down
4 changes: 2 additions & 2 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,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"]""" text text) elem
else //to preserve previous behaviour
unreliableElementsWithin (sprintf """option[text()="%s"]""" text) elem
unreliableElementsWithin (sprintf """//option[text()="%s"]""" text) elem

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

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

"double clicking" &&& fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/doubleClick"
Expand Down Expand Up @@ -486,7 +491,7 @@ context "other tests"

"count test via sizzle" &&& fun _ ->
!^ testpage
count "option:selected" 2
count "option:selected" 3

"#firstName should have John (using == infix operator), iframe1" &&& fun _ ->
url "http://lefthandedgoat.github.io/canopy/testpages/iframe1"
Expand Down

0 comments on commit 47d8cad

Please sign in to comment.