From ad2819afd0e1d5806b1e467792e08ec4539cfc11 Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Sun, 18 May 2014 14:28:38 -0500 Subject: [PATCH] Fix for #144 --- src/canopy/canopy.fs | 9 ++++++++- src/canopy/configuration.fs | 1 + tests/basictests/Program.fs | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index 9292dbf7..b0a32f21 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -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() diff --git a/src/canopy/configuration.fs b/src/canopy/configuration.fs index f46d348d..bad57482 100644 --- a/src/canopy/configuration.fs +++ b/src/canopy/configuration.fs @@ -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 \ No newline at end of file diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index f0cc30f3..fcb9245d 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -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"