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"