/// <summary>
        ///scrollBy(X,Y);unit:pixel
        /// </summary>
        /// <param name="x" ></param>
        /// <param name="y"></param>
        public void ScrollTheViewToLeftistByJs(int x, int y)
        {
            _log.Info("Start Scroll The View By JavaScript");
            var webDriver          = WebDriverHelper._webDriver;
            IJavaScriptExecutor js = webDriver as IJavaScriptExecutor;

            if (js.Equals(null))
            {
                var ex = new ArgumentException("Element", "The element must wrap a web driver that supports javascript execution.");
                _log.Error(ex.Message);
                throw ex;
            }

            //js.ExecuteScript("window.scrollBy(-100000,0)");
            js.ExecuteScript($"window.scrollBy({x},{y})");
        }
Esempio n. 2
0
        /*
         * Method : Synchronization purpose - Waits until page gets loaded
         * Params : Driver
         * Returns: Void
         */
        public void WaitForPageToLoad(int timeoutInSeconds = 200)
        {
            Log.Info("Waiting until page load is complete..");
            TimeSpan timeout = new TimeSpan(0, 0, timeoutInSeconds);

            try
            {
                WebDriverWait wait = new WebDriverWait(Driver, timeout);
                if (JsDriver.Equals(null))
                {
                    throw new ArgumentException("Driver", "Driver must support javascript execution");
                }

                wait.Until((d) =>
                {
                    try
                    {
                        string sReadyState = JsDriver.ExecuteScript("if (document.readyState) return document.readyState;").ToString();
                        return(sReadyState.ToLower() == "complete");
                    }
                    catch (InvalidOperationException e)
                    {
                        return(e.Message.ToLower().Contains("unable to get browser"));
                    }
                    catch (UnhandledAlertException e)
                    {
                        Log.Info("Alert displayed is " + e.AlertText);
                        Driver.SwitchTo().Alert().Accept();
                        return(false);
                    }
                    catch (WebDriverException e)
                    {
                        return(e.Message.ToLower().Contains("unable to connect"));
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                });
            }
            catch (WebDriverTimeoutException e)
            {
                Log.Error("Page load timed out.. " + e.Message + e.StackTrace);
                Assert.Fail("Page load timed out.. " + e.Message + e.StackTrace);
            }
        }
        public void SetAttributeByJavaScript(IWebElement element, string attributeName, string value)
        {
            try
            {
                var webDriver          = WebDriverHelper._webDriver;
                IJavaScriptExecutor js = webDriver as IJavaScriptExecutor;
                if (js.Equals(null))
                {
                    throw new ArgumentException("Element", "The element must wrap a web driver that supports javascript execution.");
                }

                js.ExecuteScript("arguments[0].setAttribute(arguments[1], arguments[2])", element, attributeName, value);
            }
            catch (Exception e)
            {
                _log.Error(e.Message, e);
                throw;
            }
        }