Skip to content

Commit

Permalink
Fix for #144
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed May 18, 2014
1 parent 35f3372 commit ad2819a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,14 @@ let last cssSelector = (List.rev (elements cssSelector)).Head

//read/write
let private writeToSelect (elem:IWebElement) (text:string) =
let options = Seq.toList (elem.FindElements(By.XPath(sprintf "option[text()='%s']" text)))
let options =
let optionsByText = unreliableElementsWithin (sprintf "option[text()='%s']" text) elem
if writeToSelectWithOptionValue then
let optionsByValue = unreliableElementsWithin (sprintf "option[value='%s']" text) elem
optionsByText @ optionsByValue
else //to preserve previous behaviour
optionsByText

match options with
| [] -> raise (CanopyOptionNotFoundException(sprintf "element %s does not contain value %s" (elem.ToString()) text))
| head::tail -> head.Click()
Expand Down
1 change: 1 addition & 0 deletions src/canopy/configuration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ let mutable disableSuggestOtherSelectors = false
let mutable autoPinBrowserRightOnLaunch = true
let mutable throwIfMoreThanOneElement = false
let mutable configuredFinders = finders.defaultFinders
let mutable writeToSelectWithOptionValue = true
6 changes: 6 additions & 0 deletions tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ waitFor condition failed to become true in 3.0 seconds"
!^ testpage
"#states" << "Kingman Reef"
"#states" == "Kingman Reef"

"writting (selecting) to drop down test, via option value, many options" &&& fun _ ->
//note that this can be turned off if its causing you problems via config.writeToSelectWithOptionValue
!^ testpage
"#states" << "95"
"#states" == "Palmyra Atoll"

"double clicking" &&& fun _ ->
!^ "http://lefthandedgoat.github.io/canopy/testpages/doubleClick"
Expand Down

0 comments on commit ad2819a

Please sign in to comment.