diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index e10be46a..1be09654 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -618,6 +618,17 @@ let ctrlClick item = true)) | _ -> raise (CanopyNotStringOrElementException(sprintf "Can't ctrlClick %O because it is not a string or webelement" item)) +let rightClick item = + let actions = Actions(browser) + + match box item with + | :? IWebElement as elem -> actions.ContextClick(elem).Perform() |> ignore + | :? string as cssSelector -> + wait elementTimeout (fun _ -> ( let elem = element cssSelector + actions.ContextClick(elem).Perform() + true)) + | _ -> raise (CanopyNotStringOrElementException(sprintf "Can't rightClick %O because it is not a string or webelement" item)) + let check item = try match box item with diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index 58ab4ba9..d69cd5a7 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -232,6 +232,15 @@ test (fun _ -> uncheck "#checkbox" element "#checkbox" |> deselected +"rightClicking Works" &&& fun _ -> + !^ "https://api.jquery.com/contextmenu/" + let iframe = element "iframe" + browser.SwitchTo().Frame(iframe) |> ignore + notDisplayed ".contextmenu" + + rightClick "div:first" + displayed ".contextmenu" + "element within only searching within the element" &&& fun _ -> url "http://lefthandedgoat.github.io/canopy/testpages/elementWithin" count ".item" 5