// Scrolling methods
        public void ScrollToElement(By locator)
        {
            AssertDisposed();
            WaitForElementPresent(locator);
            IWebElement element = WrappedDriver.FindElement(locator);

            WrappedDriver.ExecuteJavaScript <object>("arguments[0].scrollIntoView(true);", element);
            Thread.Sleep(100);
        }
 public void JsMouseOver(IWebElement element)
 {
     WrappedDriver.ExecuteJavaScript <object>(
         "var evObj = document.createEvent('MouseEvents');" +
         "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);"
         +
         "arguments[0].dispatchEvent(evObj);",
         element);
     Thread.Sleep(100);
 }
 public void SetUpTimeoutForLogOut(int timeoutMilliSeconds = s_logoutTimeout)
 {
     WrappedDriver.ExecuteJavaScript(
         $"localStorage.setItem(SESSION_STORAGE_ID, new Date().getTime() + {timeoutMilliSeconds})");
 }
 public void ScrollToTop()
 {
     AssertDisposed();
     WrappedDriver.ExecuteJavaScript("window.scrollTo(0, -document.body.scrollHeight)");
     Thread.Sleep(100);
 }
 public void ScrollToElement(IWebElement element)
 {
     AssertDisposed();
     WrappedDriver.ExecuteJavaScript <object>("arguments[0].scrollIntoView(true);", element);
     Thread.Sleep(100);
 }
 public void ExecuteJS(string script)
 {
     WrappedDriver.ExecuteJavaScript(script);
 }
 // JS methods
 public void ExecuteJS(string script,
                       IWebElement element)
 {
     WrappedDriver.ExecuteJavaScript(script, element);
 }
Beispiel #8
0
        /// <summary>
        /// The main event capture loop.
        /// </summary>
        private void captureEvents()
        {
            while (eventCaptureEnabled)
            {
                try
                {
                    //reseting iterationCompleteWaitHandle ensures that any call to suspendEventCapture while we are in the middle of the iteration will wait
                    //for the iteration to complete. A lock is not used because the critical section would indeterminately large due to the event delegate invocations.
                    iterationCompleteWaitHandle.Reset();

                    //Step 1: inject javascript which pulls off all events on the event queue and returns them. This is repeated for every event capture iteration.
                    //If the event queue code has not been registered, return a single key captureScriptNotRegistered to indicate that the script must be injected.
                    var events = WrappedDriver.ExecuteJavaScript <object>("return\"function\"==typeof getEvents?getEvents():[{captureScriptNotRegistered:null}]") as ReadOnlyCollection <object>;
                    if (events != null)
                    {
                        foreach (Dictionary <string, object> evn in events)
                        {
                            //If the event queue code has not been registered, inject it now and break the iteration. Next iteration will begin to capture events.
                            //this happens on initial WebDriver navigation or if a user event such as clicking on a link causes the browser to navigate or refresh.
                            if (evn.ContainsKey("captureScriptNotRegistered"))
                            {
                                WrappedDriver.ExecuteJavaScript("var eventQueue=[],nativeEvents={submit:\"HTMLEvents\",keypress:\"KeyEvents\",click:\"MouseEvents\",dblclick:\"MouseEvents\",contextmenu:\"MouseEvents\",dragstart:\"MouseEvents\",dragend:\"MouseEvents\",mouseover:\"MouseEvents\",mouseleave:\"MouseEvents\"};processEvent=function(e){return e.triggeredManually?!0:e.type in nativeEvents?(storeEvent(e),!1):void 0},storeEvent=function(e){ev=convertEvent(e),eventQueue.push(ev)},getEvents=function(e){var t=eventQueue.length;return eventQueue.splice(0,t)},convertEvent=function(e){var t={};return t.type=e.type,t.target=e.target,t.button=e.button,t.code=e.code,t.key=e.key,t.altKey=e.altKey,t.ctrlKey=e.ctrlKey,t.shiftKey=e.shiftKey,t.clientX=e.clientX,t.clientY=e.clientY,t.offsetX=e.offsetX,t.offsetY=e.offsetY,t};for(var eventName in nativeEvents)document.addEventListener(eventName,processEvent,!0);");
                                break;
                            }

                            //For each DOM event that was pulled off the event queue, raise the appropriate event.
                            string type = (string)evn["type"];
                            switch (type.ToLower())
                            {
                            case "click":
                                raiseMouseEvent(evn, OnElementClickCaptured);
                                break;

                            case "contextmenu":
                                raiseMouseEvent(evn, OnElementRightClickCaptured);
                                break;

                            case "dblclick":
                                raiseMouseEvent(evn, OnElementDoubleClickCaptured);
                                break;

                            case "mouseover":
                                raiseMouseEvent(evn, OnElementMouseOverCaptured);
                                break;

                            case "mouseleave":
                                raiseMouseEvent(evn, OnElementMouseLeaveCaptured);
                                break;

                            case "keypress":
                                raiseKeyboardEvent(evn, OnElementKeyPressCaptured);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.TraceError(ex.Message);
                }
                finally
                {
                    //signalling iterationCompleteWaitHandle allows the suspendEventCapture method to unblock
                    //as the iteration has safely completed.
                    iterationCompleteWaitHandle.Set();
                    if (eventCaptureEnabled)
                    {
                        Thread.Sleep(options.EventCaptureInterval);
                    }
                }

                //if suspendEventCapture has been called, the method will block here indefinitely until resumeEventCapture is called.
                //otherwise execution will pass right through to the next iteration.
                suspendWaitHandle.WaitOne();
            }
        }