Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i <= 1000; i++)
            {
                ChromeDriver chromeDriver = new ChromeDriver();
                chromeDriver.Url = "https://dev-chms.trinity.demo-application.net/public_form/add/join_cg_card";
                chromeDriver.Navigate();
                chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);



                string familyName = "f" + i;
                string givenName  = "g" + i;



                string numberPhone = "8" + (1000000 + i).ToString();
                //chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);
                chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[4]/div/input").SendKeys(familyName);
                chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[5]/div/input").SendKeys(givenName);
                chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[8]/div/input").SendKeys(numberPhone);
                // chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);

                chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[9]/div/input").SendKeys("*****@*****.**");
                //chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);

                chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[11]/div/div/input").SendKeys("Privet Driver");
                chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[12]/div/input").SendKeys("123456");

                //chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);

                var name = chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[2]/div[11]/div/div/input");
                // chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(5);

                Actions action = new Actions(chromeDriver);
                action.MoveToElement(name).Perform();

                //chromeDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10);
                //chromeDriver.Manage().Window.Maximize();
                try
                {
                    chromeDriver.ExecuteAsyncScript("jQuery('#edit-next').click();");
                }
                catch
                {
                }
                //chromeDriver.FindElementByXPath("/html/body/div[1]/div/div/div[2]/div[3]/div/div/div/div/div[3]/div[2]/form/div[3]/input").Click();


                try
                {
                    chromeDriver.ExecuteAsyncScript("jQuery('#edit-submit').click();");
                }
                catch
                {
                }
                chromeDriver.Close();
            }
        }
Exemplo n.º 2
0
        private void FinishRace()
        {
            IWebElement inputTextbox  = webDriver.FindElement(By.XPath(XPaths.inputTextbox));
            IWebElement textContainer = webDriver.FindElement(By.XPath(XPaths.textContainer));

            if (!Configuration.instantMode)
            {
                try
                {
                    string text = textContainer.Text;
                    int    msDelay;
                    int    cpm = Configuration.wpm * 6;             // 1 word = 5 characters
                    msDelay = (int)Math.Round(60d / cpm * 1000, 0); //60 seconds divided by letters per minute times 1000 for ms
                    Console.WriteLine();
                    foreach (char c in text)
                    {
                        inputTextbox.SendKeys(c.ToString());
                        Thread.Sleep(msDelay);
                    }
                    inputTextbox.Click();
                }
                catch (ElementNotInteractableException) { }
                catch (UnhandledAlertException) { }
            }
            else
            {
                string jscode = $"(document.evaluate(\"{XPaths.inputTextbox}\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).value = \"{textContainer.Text}\";";
                try
                {
                    webDriver.ExecuteAsyncScript(jscode);
                    inputTextbox.Click();
                }
                catch (WebDriverTimeoutException) { }
                catch (UnhandledAlertException) { }
            }
            Thread.Sleep(300);
            if (Configuration.autorace)
            {
                try
                {
                    webDriver.FindElement(By.ClassName("raceAgainLink")).Click();
                    if (!accountPopupClosed)
                    {
                        try
                        {
                            var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(1));
                            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//a[text()='No thanks :(']"))).Click();
                            accountPopupClosed = true;
                        }
                        catch (WebDriverTimeoutException) { }
                    }
                }
                catch (UnhandledAlertException) { }
                catch (ElementNotInteractableException) { }
            }
            WaitForRaceStart();
        }
Exemplo n.º 3
0
        public override bool execute(Script script)
        {
            try
            {
                string serverTime = null;
                try
                {
                    serverTime = (string)driver.ExecuteAsyncScript(@"var done=arguments[arguments.length-1];$.get('/exchange/public/serverTime').then(function(resp){var date=new Date(resp);var time=date.toTimeString().match('\.+? ')[0].trim();done(time);});");
                }
                catch (Exception e)
                {
                    Console.Out.WriteLine(e);
                }

                if (script.time.Equals(serverTime))
                {
                    driver.Manage().Timeouts().SetScriptTimeout(new TimeSpan(0, 0, 0, 0, 0));

                    var prices     = new string[script.jobs.Count];
                    var quantities = new string[script.jobs.Count];
                    var symbols    = new string[script.jobs.Count];
                    var sides      = new string[script.jobs.Count];

                    for (int i = 0; i < script.jobs.Count; i++)
                    {
                        var job = script.jobs[i];
                        prices[i]     = job.price;
                        quantities[i] = job.count;
                        symbols[i]    = job.code;
                        sides[i]      = job.side;
                    }

                    // 执行时间匹配,开始执行
                    try
                    {
                        driver.ExecuteAsyncScript(Resources.order, script.times, script.interval, script.orderWait, script.jobs.Count, prices, quantities, symbols, sides);
                    }
                    catch (Exception e)
                    {
                        Console.Out.WriteLine(e);
                    }

                    return(true);
                }
                else
                {
                    // 执行时间不匹配,等待下一次
                    return(false);
                }
            }
            catch (Exception e)
            {
                // 出现异常,终止脚本
                throw e;
            }
        }
Exemplo n.º 4
0
 public void Eval()
 {
     try
     {
         if (IsAsync)
         {
             string asyncScript = String.Format(@"var ret = {0}; var callback = arguments[arguments.length-1]; callback(ret);", Script);
             object ret         = chromeDriver.ExecuteAsyncScript(asyncScript);
             MessageBox.Show(ret as string);
         }
         else
         {
             string syncScript = String.Format(@"return {0}", Script);
             object ret        = chromeDriver.ExecuteScript(syncScript);
             MessageBox.Show(ret as string);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }