示例#1
0
        public override bool Execute(PhantomJSDriver driver)
        {
            IWebElement element = null;

            try
            {
                switch (Parameters[0])
                {
                case "id":
                    element = driver.FindElementById(Parameters[1]);
                    break;

                case "name":
                    element = driver.FindElementByName(Parameters[1]);
                    break;

                case "class":
                    element = driver.FindElementByClassName(Parameters[1]);
                    break;

                case "text":
                    element = driver.FindElementByLinkText(Parameters[1]);
                    break;
                }
            }
            catch (Exception e)
            {
                //Element was not found
                return(false);
            }

            //Wrong parameters were used
            return(element != null);
        }
示例#2
0
        private void writeToHA(string scopename)
        {
            var table          = driver.FindElementByClassName("table-container");
            var tr             = table.FindElement(By.CssSelector(".aver"));
            var child          = tr.FindElements(By.XPath(".//td"));
            var AverageX       = child[1].Text;
            var AverageY       = child[2].Text;
            var AveragePercent = child[3].Text;



            tr    = table.FindElement(By.CssSelector(".highest"));
            child = tr.FindElements(By.XPath(".//td"));
            var highestX       = child[1].Text;
            var highestY       = child[2].Text;
            var highestPercent = child[3].Text;

            tr    = table.FindElement(By.CssSelector("tr.foot.predictions"));
            child = tr.FindElements(By.XPath(".//td"));
            var userpredX = child[1].Text;

            userpredX = userpredX.Split('\r')[0];
            var userpredY = child[2].Text;

            userpredY = userpredY.Split('\r')[0];

            writer.writeToHA(match_id, scopename, AverageX, AverageY, AveragePercent, highestX, highestY, highestPercent, userpredX, userpredY);
        }
示例#3
0
        public override bool Execute(PhantomJSDriver driver)
        {
            IWebElement element = null;

            switch (Parameters[0])
            {
            case "id":
                element = driver.FindElementById(Parameters[1]);
                break;

            case "class":
                element = driver.FindElementByClassName(Parameters[1]);
                break;

            case "tag":
                element = driver.FindElementByTagName(Parameters[1]);
                break;

            case "text":
                element = driver.FindElementByLinkText(Parameters[1]);
                break;

            case "name":
                element = driver.FindElementByName(Parameters[1]);
                break;

            default:
                return(false);
            }

            //Element not found
            if (element == null)
            {
                return(false);
            }
            try
            {
                element.Click();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
                //Element not clickable
            }
        }
示例#4
0
        private static string GetTokenFromUrl(string url, string username, string password)
        {
            var driverService = PhantomJSDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;

            driverService.LoadImages      = false;
            driverService.SslProtocol     = "tlsv1";
            driverService.IgnoreSslErrors = true;
            driverService.ProxyType       = "https";
            driverService.Proxy           = "";

            using (var phantom = new PhantomJSDriver(driverService))
            {
                phantom.Manage().Cookies.DeleteAllCookies();
                phantom.Navigate().GoToUrl(url);

                var userField   = phantom.FindElementById("id_username");
                var passField   = phantom.FindElementById("id_password");
                var loginButton = phantom.FindElementByClassName("button-green");

                userField.SendKeys(username);
                passField.SendKeys(password);
                loginButton.Click();

                //https://www.google.es/?gws_rd=ssl#access_token=1092362346.6a5985a.584f9dfd6b88426a8e155ef68b443b2c
                Regex regex = new Regex(@"access_token=\S+$");
                var   match = regex.Match(phantom.Url);

                if (match.Success)
                {
                    return(match.Value.Substring("access_token=".Length));
                }

                Assert.Fail("No token found on " + phantom.Url);

                return("");
            }
        }