Beispiel #1
0
        public override void getRndValue(ComboBox cbResource, Label resultRnd, int valMin, int valMax)
        {
            string resourceName = cbResource.Text;
            string url;

            using (RNDDBEntities db = new RNDDBEntities())
            {
                Resource model = (from u in db.Resource
                                  where u.name == resourceName
                                  select u).FirstOrDefault();
                url = model.url;
            }
            ChromeOptions chromeOptions = new ChromeOptions();
            //chromeOptions.AddArguments("headless");
            ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;
            ChromeDriver  browser = new ChromeDriver(driverService, chromeOptions);
            WebDriverWait wait    = new WebDriverWait(browser, TimeSpan.FromSeconds(10));

            browser.Navigate().GoToUrl(url);
            IWebElement button = wait.Until(e => e.FindElement(By.CssSelector("#button")));

            button = browser.FindElement(By.CssSelector("#button"));
            IWebElement imputMin = wait.Until(e => e.FindElement(By.CssSelector("#number-start")));

            imputMin.Click();
            imputMin.Clear();
            imputMin.SendKeys(valMin.ToString());
            IWebElement imputMax = wait.Until(e => e.FindElement(By.CssSelector("#number-end")));

            imputMax.Click();
            imputMax.Clear();
            imputMax.SendKeys(valMax.ToString());
            button.Click();
            IWebElement getValue = wait.Until(e => e.FindElement(By.CssSelector(".new")));

            resultRnd.Text = getValue.GetAttribute("innerText");
            browser.Close();
        }
Beispiel #2
0
        private void addHistory()
        {
            history.range_min = valMin;
            history.range_max = valMax;
            history.result    = Convert.ToInt32(resultRnd.Text);

            using (RNDDBEntities db = new RNDDBEntities())
            {
                History model = (from u in db.History
                                 orderby u.number_rnd descending
                                 select u).FirstOrDefault();
                if (model != null)
                {
                    history.number_rnd = model.number_rnd + 1;
                }
                else
                {
                    history.number_rnd = 1;
                }
            }

            using (RNDDBEntities db = new RNDDBEntities())
            {
                Resource model = (from u in db.Resource
                                  where u.name == resource
                                  select u).FirstOrDefault();
                history.url_id = model.id;
            }


            using (RNDDBEntities db = new RNDDBEntities())
            {
                db.History.Add(history);
                db.SaveChanges();
            }
        }