Skip to content

Commit

Permalink
fix for #229
Browse files Browse the repository at this point in the history
  • Loading branch information
lefthandedgoat committed Jan 19, 2016
1 parent 9beed33 commit af66cc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,23 @@ let private textOf (element : IWebElement) =
| _ ->
element.Text

let private safeRead item =
let readvalue = ref ""
try
wait elementTimeout (fun _ ->
readvalue :=
match box item with
| :? IWebElement as elem -> textOf elem
| :? string as cssSelector -> element cssSelector |> textOf
true)
!readvalue
with
| :? WebDriverTimeoutException -> raise (CanopyReadException("was unable to read item for unkown reason"))
let read item =
match box item with
| :? IWebElement as elem -> textOf elem
| :? string as cssSelector -> element cssSelector |> textOf
| :? IWebElement as elem -> safeRead elem
| :? string as cssSelector -> safeRead cssSelector
| _ -> raise (CanopyNotStringOrElementException(sprintf "Can't read %O because it is not a string or element" item))
let clear item =
Expand Down Expand Up @@ -827,7 +840,7 @@ let addFinder finder =

//hints
let private addHintFinder hints finder = hints |> Seq.append (seq { yield finder })
let private addSelector finder hintType selector =
let addSelector finder hintType selector =
//gaurd against adding same hintType multipe times and increase size of finder seq
if not <| (hints.ContainsKey(selector) && addedHints.[selector] |> List.exists (fun hint -> hint = hintType)) then
if hints.ContainsKey(selector) then
Expand Down
1 change: 1 addition & 0 deletions src/canopy/types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type CanopyNotStringOrElementException(message) = inherit CanopyException(messag
type CanopyOnException(message) = inherit CanopyException(message)
type CanopyCheckFailedException(message) = inherit CanopyException(message)
type CanopyUncheckFailedException(message) = inherit CanopyException(message)
type CanopyReadException(message) = inherit CanopyException(message)

//directions
type direction =
Expand Down

0 comments on commit af66cc8

Please sign in to comment.