diff --git a/docs/content/actions.fsx b/docs/content/actions.fsx index 3e87851c..356a4576 100644 --- a/docs/content/actions.fsx +++ b/docs/content/actions.fsx @@ -454,6 +454,14 @@ let browser3 = browser tile [browser1; browser2; browser3] +(** +positionBrowser +---- +Position current browser on the screen - position is in percentages: positionBrowser left top width height +*) +positionBrowser 66 0 33 50 + + (** currentUrl ---------- diff --git a/src/canopy/canopy.fs b/src/canopy/canopy.fs index b4b89395..787bc1da 100644 --- a/src/canopy/canopy.fs +++ b/src/canopy/canopy.fs @@ -862,6 +862,20 @@ let tile (browsers : IWebDriver list) = setSize browsers 0 +(* documented/actions *) +let positionBrowser left top width height = + let h = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height + let w = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width + + let x = left * w / 100 + let y = top * h / 100 + let bw = width * w /100 + let bh = height * h / 100 + + browser.Manage().Window.Size <- new System.Drawing.Size(bw, bh) + browser.Manage().Window.Position <- new System.Drawing.Point(x, y) + + let private innerSize() = let jsBrowser = browser :?> IJavaScriptExecutor let innerWidth = System.Int32.Parse(jsBrowser.ExecuteScript("return window.innerWidth").ToString())