예제 #1
0
        static async Task Main(string[] args)
        {
            IWebDriver    driver        = new ChromeDriver();
            WebDriverWait wait          = new WebDriverWait(driver, TimeSpan.FromSeconds(0));
            WebClient     wc            = new WebClient();
            HtmlWeb       web           = new HtmlWeb();
            int           allPicsNumber = 0;
            int           allCarsNumber = 0;

            string autoGyarto = "";
            string autoTipus  = "";

            /*
             *
             * 1. Re-Do  the algorhythm to traverse the website with the Models at hand.
             * 2. Add the created használtauto-s to the database
             *      - Create a NrOfdays column to our database, representing the number of days this particular car is online
             *      - Check if a record already exists, if so update that record -> NrOfDays += 1
             *      - Make the proper checks before adding them
             * 3. Get a propert virtual machine and set up an sql database so you can handle the data online.
             */

            HasznaltautoHandler hh = new HasznaltautoHandler();



            driver.Url = "https://www.hasznaltauto.hu/";

            #region Maximize & Click Cookie
            driver.Manage().Window.Maximize();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
            IWebElement cookieOK = driver.FindElement(By.Id("CybotCookiebotDialogBodyButtonAccept"));
            cookieOK.Click();
            #endregion

            Thread.Sleep(250);
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);

            #region Main page, select a car brand
            IWebElement   carBrand          = driver.FindElement(By.Id("hirdetesszemelyautosearch-marka_id"));
            SelectElement carBrandSelector  = new SelectElement(carBrand);
            int           numberOfCarBrands = carBrandSelector.Options.Count;
            #endregion

            #region Going through each brand 1 by 1
            for (int i = 1; i < 7; i++) //numberOfCarBrands
            {
                Thread.Sleep(250);
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);

                IWebElement   carBrandNOTstale         = driver.FindElement(By.Id("hirdetesszemelyautosearch-marka_id"));
                SelectElement carBrandSelectorNOTstale = new SelectElement(carBrandNOTstale);
                carBrandSelectorNOTstale.SelectByIndex(i);
                autoGyarto = carBrandSelectorNOTstale.SelectedOption.Text;

                IWebElement   carType          = driver.FindElement(By.Id("hirdetesszemelyautosearch-modell_id"));
                SelectElement carTypeSelector  = new SelectElement(carType);
                int           numberOfCarTypes = carTypeSelector.Options.Count;

                for (int l = 1; l < numberOfCarTypes; l++)
                {
                    Thread.Sleep(250);
                    IWebElement   carBrandNOTstaleagain         = driver.FindElement(By.Id("hirdetesszemelyautosearch-marka_id"));
                    SelectElement carBrandSelectorNOTstaleagain = new SelectElement(carBrandNOTstaleagain);
                    carBrandSelectorNOTstaleagain.SelectByIndex(i);
                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);
                    Thread.Sleep(750);

                    IWebElement   carTypeNOTstale         = driver.FindElement(By.Id("hirdetesszemelyautosearch-modell_id"));
                    SelectElement carTypeSelectorNOTstale = new SelectElement(carTypeNOTstale);
                    wait.Until(driver => carTypeSelectorNOTstale.Options.Count > 1);

                    carTypeSelectorNOTstale.SelectByIndex(l);
                    autoTipus = carTypeSelectorNOTstale.SelectedOption.Text;

                    Thread.Sleep(450);

                    IWebElement btnKereses = driver.FindElement(By.Name("submitKereses"));
                    btnKereses.SendKeys(Keys.Control + "t");
                    btnKereses.Click();

                    int  maximumNumberOfPages = 1;
                    bool pagination           = IsPaginationPresent(driver, By.ClassName("pagination"));
                    if (pagination)
                    {
                        maximumNumberOfPages = Convert.ToInt32(driver.FindElement(By.XPath(@"//li[@class='last']/a")).Text);
                    }
                    int k = 0;
                    do
                    {
                        wait.Until(driver => driver.FindElement(By.CssSelector(@".col-xs-28.col-sm-19.cim-kontener")).Displayed);
                        int numberOfCarsInOnePage = driver.FindElements(By.CssSelector(@".col-xs-28.col-sm-19.cim-kontener")).Count;
                        #region Car page
                        for (int j = 0; j < numberOfCarsInOnePage; j++)
                        {
                            Thread.Sleep(250);
                            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3);

                            wait.Until(driver => driver.FindElement(By.CssSelector(@".col-xs-28.col-sm-19.cim-kontener")).Displayed);
                            ReadOnlyCollection <IWebElement> listOfCarsInOnePageNOTstale = driver.FindElements(By.CssSelector(@".col-xs-28.col-sm-19.cim-kontener"));
                            //.col-sm-19.cim-kontener

                            IWebElement onecarFromList = listOfCarsInOnePageNOTstale[j].FindElement(By.TagName("h3"));
                            //(@"//div[@class='row talalati-sor swipe-watch kiemelt']//h3"));
                            IWebElement carCardLink = onecarFromList.FindElement(By.TagName("a"));
                            var         carLink     = carCardLink.GetAttribute("href");

                            string[] hirdetesLink = carLink.Split('-');
                            string   hirdetesKod  = hirdetesLink[hirdetesLink.Length - 1];

                            /*
                             * I have the text of the link of a specific car
                             * If the 'hirdeteskod' on the car card doesn't exist in my database, navigate to the above said link
                             */

                            using (HasznaltautoContext hnc = new HasznaltautoContext())
                            {
                                var doesAutoAlreadyExistInDataBase = hnc.Hasznaltauto.Where <Hasznaltauto>(p => p.Hirdeteskod == hirdetesKod).Any();
                                if (!doesAutoAlreadyExistInDataBase)
                                {
                                    Console.WriteLine($"Uj autot találtam: Ezzel a hirdetéskoddal: {hirdetesKod}");
                                    carCardLink.Click();
                                    #region Instantiating HasznaltAuto
                                    HasznaltautoAdapter hasznaltautoAdapter = new HasznaltautoAdapter(carLink, autoGyarto, autoTipus);
                                    try
                                    {
                                        Hasznaltauto hasznaltAuto = hasznaltautoAdapter.CreateHasznaltauto();
                                        allCarsNumber++;
                                        hnc.SaveChanges();
                                        Console.WriteLine($"Number of CARS added so far: {allCarsNumber}");
                                        hnc.Hasznaltauto.Add(hasznaltAuto);

                                        int numberOfImages = Int32.Parse(driver.FindElement(By.ClassName("hirdetes-kepek")).Text);
                                        Console.WriteLine(numberOfImages);

                                        //HAS TO BE ASNYC OR THREADED
                                        //allPicsNumber = UploadImagesToDatabase(numberOfImages, driver, hasznaltAuto, allPicsNumber, hnc);

                                        if (numberOfImages != 0)
                                        {
                                            var links = from b in driver.FindElements(By.TagName("a"))  //driver.FindElements(By.XPath(@"//div[@class='slide']"))
                                                        where b.GetAttribute("data-size") == "640x480"  //("data-index") == z.ToString()
                                                        select(string) b.GetAttribute("href");

                                            List <string> listOfImageURI = links.ToList();
                                            if (listOfImageURI.Any())
                                            {
                                                ////Console.WriteLine(firstImagesURIString);
                                                for (int z = 0; z < numberOfImages; z++)
                                                {
                                                    Kepek  kep      = new Kepek();
                                                    string imageURI = listOfImageURI[z];

                                                    //Trying out things
                                                    //kep.Hasznaltauto = hasznaltAuto;
                                                    //kep.HasznaltautoId = hasznaltAuto.HasznaltautoId;
                                                    //kep.Hirdeteskod = hasznaltAuto.Hirdeteskod;
                                                    //kep.Img = imageURI;
                                                    ////kep.Hash = await GetHash(imageURI);

                                                    //allPicsNumber++;
                                                    //hnc.Kepek.Add(kep);
                                                    //hnc.SaveChanges();
                                                    //Trying out things

                                                    await kep.SaveImageToDatabase(kep, hasznaltAuto, allPicsNumber, imageURI, hnc);

                                                    Console.WriteLine($"Number of pictures added so far: {allPicsNumber}");
                                                    allPicsNumber++;
                                                }
                                            }
                                        }
                                        hnc.SaveChanges();
                                        driver.Navigate().Back();
                                    }
                                    catch (ArgumentException ex)
                                    {
                                        Console.WriteLine(ex.Message);
                                    }
                                }
                                #endregion
                            }
                        }
                        k++;
                        //Click on the next page button
                        var pages = driver.FindElements(By.XPath(@"//ul['pagination']/li"));
                        if (maximumNumberOfPages != 1)
                        {
                            var page = driver.FindElement(By.CssSelector(@".lapozoNyilJobb.haicon-uj-jnyil-kicsi"));
                            page.Click();
                        }
                        #endregion
                    } while (k < maximumNumberOfPages);
                    driver.FindElement(By.CssSelector(".navbar-brand.navbar-brand-hza")).Click();
                }
            }
            #endregion
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.Write("Login ID:");
            var id = Console.ReadLine();

            Console.Write("Password:"******"--log-level=3");
            var driver = new ChromeDriver(options);

            try
            {
                driver.Navigate().GoToUrl("https://elearn.cuhk.edu.hk");
                driver.FindElementByName("username").SendKeys(id);
                driver.FindElementByName("password").SendKeys(password);
                driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr[1]/td[1]/table/tbody/tr[2]/td/form/table/tbody/tr[6]/td/input[1]").Submit();
                IWebElement table     = new WebDriverWait(driver, TimeSpan.FromMilliseconds(100000)).Until(ExpectedConditions.ElementExists(By.ClassName("portletList-img")));
                var         course_li = driver.FindElementsByCssSelector(".portletList-img > li");
                for (int i = 1; i <= course_li.Count(); i++)
                {
                    IWebElement wait        = new WebDriverWait(driver, TimeSpan.FromMilliseconds(100000)).Until(ExpectedConditions.ElementExists(By.ClassName("portletList-img")));
                    var         course_link = driver.FindElementByXPath("//*[@id='_4_1termCourses_noterm']/ul/li[" + i + "]/a");
                    string      course_text = course_link.Text;
                    try
                    {
                        course_link.Click();
                        IList <IWebElement> elements = driver.FindElements(By.CssSelector("#courseMenuPalette_contents > li > a[href*=webapps]"));
                        List <string>       xpaths   = new List <string>();
                        foreach (var element in elements)
                        {
                            xpaths.Add(GetElementXPath(driver, element));
                        }
                        List <string> except_text = new List <string>(new string[] { "Notifications", "Announcements", "Discussion Board", "Notifications", "Email", "Groups", "My Grades" });
                        foreach (var element in xpaths)
                        {
                            if (driver.FindElementByXPath(element).GetAttribute("href").Contains("displayName"))
                            {
                                continue;
                            }
                            if (!except_text.Contains(driver.FindElementByXPath(element).Text))
                            {
                                driver.FindElementByXPath(element).Click();
                                download_file(element, driver, driver.FindElementByXPath(element).Text);
                            }
                        }

                        driver.Navigate().GoToUrl("https://elearn.cuhk.edu.hk");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Some file in " + course_text + "cannot be dowloaded.  Please check.");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                driver.Quit();
            }
            driver.Quit();
            Console.WriteLine("Press ENTER to close console......");
            ConsoleKeyInfo keyInfo = Console.ReadKey();

            while (keyInfo.Key != ConsoleKey.Enter)
            {
                keyInfo = Console.ReadKey();
            }
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            jobs.Clear();
            selectedShift.Text   = "";
            calendar.BoldedDates = null;
            if (fiveDayInc.Checked == false && tenDayInc.Checked == false && twentyDayInc.Checked == false && thirtyDayInc.Checked == false)
            {
                MessageBox.Show("Please select the number of days you'd like to search through.");
            }
            else
            {
                excelView.Visible   = true;
                notepadView.Visible = true;
                label5.Visible      = true;
                reset.Visible       = true;
                lines = System.IO.File.ReadAllLines(@"userData.txt");
                String     fName  = lines[0];
                String     lName  = lines[1];
                IWebDriver driver = new ChromeDriver();
                driver.Url = "http://172.21.20.41/cepdotnet/CEPloginToCEP.aspx";

                IWebElement username = driver.FindElement(By.Id("txtUserName"));
                IWebElement password = driver.FindElement(By.Id("txtPassword"));

                username.Clear();
                username.SendKeys(lines[2]);

                password.Clear();
                password.SendKeys(lines[3]);

                IWebElement lgnBtn = driver.FindElement(By.Id("sbtLogin"));
                lgnBtn.Click();

                ReadOnlyCollection <IWebElement> elements;

                int cMonth = DateTime.Now.Month, cDay = DateTime.Now.Day, cYear = DateTime.Now.Year, dateCounter = 0, scheduledDatesIndex = 0;;
                if (fiveDayInc.Checked)
                {
                    dateCounter = 5;
                }
                else if (tenDayInc.Checked)
                {
                    dateCounter = 10;
                }
                else if (twentyDayInc.Checked)
                {
                    dateCounter = 20;
                }
                else if (thirtyDayInc.Checked)
                {
                    dateCounter = 30;
                }


                System.DateTime[] scheduledDates = new System.DateTime[dateCounter];

                String[] tempElementArray = null, tempStringDateTime;
                String   tempJobName;
                bool     tempCancelled = false;
                int      tempHour, indexChange, tempMin, tempMonth;
                Job      tempJob    = null;
                Person   tempPerson = null;

                for (int i = dateCounter; i > 0; i--)
                {
                    driver.Url = "http://172.21.20.41/cepdotnet/CEPHome.aspx?day=" + cDay + "&month=" + cMonth + "&year=" + cYear;

                    elements = driver.FindElements(By.XPath("//*[contains(text(), '" + fName + "') and contains(text(), '" + lName + "')]/ancestor::tbody[1]"));

                    try
                    {
                        if (elements[0] != null)
                        {
                            scheduledDates[scheduledDatesIndex] = new System.DateTime(cYear, cMonth, cDay, 0, 0, 0, 0);
                            scheduledDatesIndex++;
                        }
                    }
                    catch (Exception)
                    {
                        tempElementArray = null;
                    }


                    tempJob = null;
                    foreach (IWebElement element in elements)
                    {
                        //for midnight and noon time
                        indexChange = 0;

                        //split job into array of String values
                        tempElementArray = element.Text.Split(new char[] { '\n' });

                        //analyze name
                        if (tempElementArray[0].Contains("CANCELLED"))
                        {
                            tempJobName   = tempElementArray[0].Substring(0, tempElementArray[0].IndexOf("CANCELLED"));
                            tempCancelled = true;
                        }
                        else
                        {
                            tempJobName   = tempElementArray[0];
                            tempCancelled = false;
                        }

                        //analyze datetime of job
                        tempStringDateTime = tempElementArray[1].Trim().Split(new char[] { ' ' });

                        //analyze time
                        if (tempStringDateTime[0].Equals("NOON"))
                        {
                            indexChange = 1;
                            tempHour    = 12;
                            tempMin     = 0;
                        }
                        else if (tempStringDateTime[0].Equals("MIDNIGHT"))
                        {
                            indexChange = 1;
                            tempHour    = 0;
                            tempMin     = 0;
                        }
                        else
                        {
                            tempHour = int.Parse(tempStringDateTime[0].Substring(0, tempStringDateTime[0].IndexOf(":")));
                            if (tempStringDateTime[1].Equals("PM"))
                            {
                                tempHour += 12;

                                //this is more for rare errors in code analyis it is barely used
                                if (tempHour >= 24)
                                {
                                    tempHour -= 24;
                                }
                            }
                            tempMin = int.Parse(tempStringDateTime[0].Substring(tempStringDateTime[0].IndexOf(":") + 1));
                        }

                        //get month int
                        if (tempStringDateTime[3 - indexChange].Equals("January"))
                        {
                            tempMonth = 1;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("February"))
                        {
                            tempMonth = 2;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("March"))
                        {
                            tempMonth = 3;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("April"))
                        {
                            tempMonth = 4;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("May"))
                        {
                            tempMonth = 5;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("June"))
                        {
                            tempMonth = 6;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("July"))
                        {
                            tempMonth = 7;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("August"))
                        {
                            tempMonth = 8;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("September"))
                        {
                            tempMonth = 9;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("October"))
                        {
                            tempMonth = 10;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("November"))
                        {
                            tempMonth = 11;
                        }
                        else if (tempStringDateTime[3 - indexChange].Equals("December"))
                        {
                            tempMonth = 12;
                        }
                        else
                        {
                            tempMonth = 0;
                        }

                        tempJob = new Job(tempJobName, new DateTime(int.Parse(tempStringDateTime[5 - indexChange]), tempMonth, int.Parse(tempStringDateTime[4 - indexChange].Substring(0, tempStringDateTime[4 - indexChange].IndexOf(","))), tempHour, tempMin, 0, 0), tempCancelled);



                        //grab workers
                        for (int tempElementArrayIndex = 3; tempElementArrayIndex < tempElementArray.Length; tempElementArrayIndex++)
                        {
                            tempElementArray[tempElementArrayIndex] = tempElementArray[tempElementArrayIndex].Trim();

                            //reuse for name and start and stop times
                            tempStringDateTime = tempElementArray[tempElementArrayIndex].Trim().Split(new char[] { ' ' });

                            tempPerson = new Person(tempStringDateTime[0], tempStringDateTime[1]);

                            indexChange = 0;

                            //analyze worker start time
                            if (tempStringDateTime[2].Equals("NOON"))
                            {
                                indexChange = 1;
                                tempHour    = 12;
                                tempMin     = 0;
                            }
                            else if (tempStringDateTime[2].Equals("MIDNIGHT"))
                            {
                                indexChange = 1;
                                tempHour    = 0;
                                tempMin     = 0;
                            }
                            else
                            {
                                tempHour = int.Parse(tempStringDateTime[2].Substring(0, tempStringDateTime[2].IndexOf(":")));
                                if (tempStringDateTime[3].Equals("PM"))
                                {
                                    tempHour += 12;

                                    //this is more for rare errors in code analyis it is barely used
                                    if (tempHour >= 24)
                                    {
                                        tempHour -= 24;
                                    }
                                }
                                tempMin = int.Parse(tempStringDateTime[2].Substring(tempStringDateTime[2].IndexOf(":") + 1));
                            }

                            if (tempMin == 0)
                            {
                                tempHour *= 100;
                            }
                            else if (tempMin < 10)
                            {
                                tempHour = tempHour * 100 + tempMin;
                            }
                            else
                            {
                                tempHour = tempHour * 100 + tempMin;
                            }

                            //set person attributes
                            tempPerson.setStartTime(tempHour);



                            //analyze worker start time
                            if (tempStringDateTime[4 - indexChange].Equals("NOON"))
                            {
                                tempHour = 12;
                                tempMin  = 0;
                            }
                            else if (tempStringDateTime[4 - indexChange].Equals("MIDNIGHT"))
                            {
                                tempHour = 0;
                                tempMin  = 0;
                            }
                            else
                            {
                                tempHour = int.Parse(tempStringDateTime[4 - indexChange].Substring(0, tempStringDateTime[4 - indexChange].IndexOf(":")));
                                if (tempStringDateTime[5 - indexChange].Equals("PM"))
                                {
                                    tempHour += 12;

                                    //this is more for rare errors in code analyis it is barely used
                                    if (tempHour >= 24)
                                    {
                                        tempHour -= 24;
                                    }
                                }
                                tempMin = int.Parse(tempStringDateTime[4 - indexChange].Substring(tempStringDateTime[4 - indexChange].IndexOf(":") + 1));
                            }

                            if (tempMin == 0)
                            {
                                tempHour *= 100;
                            }
                            else if (tempMin < 10)
                            {
                                tempHour = tempHour * 100 + tempMin;
                            }
                            else
                            {
                                tempHour = tempHour * 100 + tempMin;
                            }

                            //set person attributes
                            tempPerson.setEndTime(tempHour);

                            //add temp person to job
                            tempJob.addWorker(tempPerson);
                        }
                        //end job add for day
                        if (tempJob != null)
                        {
                            jobs.Add(tempJob);
                        }
                    }



                    cDay++;
                    int daysInMonth = System.DateTime.DaysInMonth(cYear, cMonth);
                    if (cDay > daysInMonth)
                    {
                        cDay = 1;
                        cMonth++;
                        if (cMonth > 12)
                        {
                            cMonth = 1;
                            cYear++;
                        }
                    }
                }

                //setup calendar
                calendar.BoldedDates = scheduledDates;
                driver.Quit(); //Quits chrome and CMD
            }
        }
예제 #4
0
        static void Scraping()
        {
            ChromeOptions opciones = new ChromeOptions();

            opciones.AddArgument("--headless");
            IWebDriver driver = new ChromeDriver(opciones);

            driver.Url = "http://books.toscrape.com/";

            // Hago scraping de las categorias y obtengo los datos CategoriaID, Nombre, Url
            var ligascat = driver.FindElements(By.XPath("/html/body/div/div/div/aside/div[2]/ul/li/ul/li/a"));
            List <Categoria> categorias = new List <Categoria>();

            foreach (var l in ligascat)
            {
                Categoria categoria = new Categoria();
                var       url       = l.GetAttribute("href");
                var       i         = url.LastIndexOf("_") + 1;
                var       f         = url.LastIndexOf("/") - i;
                categoria.CategoriaID = int.Parse(url.Substring(i, f));
                categoria.Nombre      = l.Text;
                categoria.Url         = url;
                categorias.Add(categoria);
            }

            // Hacemos scraping de los libros dentro de cada categoria
            List <Libro>  libros     = new List <Libro>();
            List <string> urlspagina = new List <string>();

            for (int i = 1; i <= 50; i++)
            {
                urlspagina.Add($"http://books.toscrape.com/catalogue/page-{i}.html");
            }
            foreach (var urlp in urlspagina)
            {
                driver.Navigate().GoToUrl(urlp);
                List <string> urlslibro  = new List <string>();
                var           ligaslibro = driver.FindElements(By.XPath("/html/body/div/div/div/div/section/div[2]/ol/li/article/h3/a"));
                foreach (var l in ligaslibro)
                {
                    urlslibro.Add(l.GetAttribute("href"));
                }
                foreach (var url in urlslibro)
                {
                    driver.Navigate().GoToUrl(url);
                    Libro libro = new Libro();
                    libro.Url       = url;
                    libro.UrlImagen = driver.FindElement(By.XPath("/html/body/div/div/div[2]/div[2]/article/div[1]/div[1]/div/div/div/div/img")).GetAttribute("src");
                    libro.Titulo    = driver.FindElement(By.XPath("/html/body/div/div/div[2]/div[2]/article/div[1]/div[2]/h1")).Text;
                    libro.Precio    = decimal.Parse(driver.FindElement(By.XPath("/html/body/div/div/div[2]/div[2]/article/div[1]/div[2]/p[1]")).Text.Replace('£', ' '));
                    var catidliga = driver.FindElement(By.XPath("/html/body/div/div/ul/li[3]/a")).GetAttribute("href");
                    var i         = catidliga.LastIndexOf("_") + 1;
                    var f         = catidliga.LastIndexOf("/") - i;
                    libro.CategoriaID = int.Parse(catidliga.Substring(i, f));
                    libros.Add(libro);
                }
            }

            // Vacia las categorias obtenidas al objeto que represnta la tabla de BD
            db.Database.EnsureCreated(); // si la bd no existe la crea
            foreach (var c in categorias)
            {
                db.Categorias.Add(c);
            }
            foreach (var l in libros)
            {
                db.Libros.Add(l);
            }

            db.SaveChanges();
        }
        /*
         * author : yuha
         * funcName : crawlingFromkream
         * summary : kream 크롤링
         * input :  searchVo
         * return : Dictionary<string, DetailInfo>
         */
        public Dictionary <string, DetailInfo> crawlingFromkream(SearchVo searchVo)
        {
            /*kream 정보 수집 시작*/
            _driver = new ChromeDriver(_driverService, _options);
            _driver.Navigate().GoToUrl(searchVo.kreamUrl); // 웹 사이트에 접속합니다.
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            //searchVo.kreamUrl = "https://kream.co.kr/products/23219";

            var thumbnailUrl = _driver.FindElementsByClassName("product_img")[0].GetAttribute("src");

            searchVo.thumbnailUrl = thumbnailUrl;
            string sizeType = searchVo.sizeType;

            Dictionary <string, string> krUsSizeMap = sizeConstantMap.getKrUsSizeMap();

            if (sizeType.Contains("W"))
            {
                krUsSizeMap = sizeConstantMap.getKrUsSizeWMap();
            }
            else if (sizeType.Contains("Y"))
            {
                krUsSizeMap = sizeConstantMap.getKrUsSizeYMap();
            }
            else if (searchVo.clothesYn)
            {
                krUsSizeMap = sizeConstantMap.getClothesSizeMap();
            }

            var sizeButton = _driver.FindElement(By.XPath("//a[@class='btn_size']"));
            //var buttonList = _driver.FindElements(By.XPath("//button[@class='select_link']"));

            Dictionary <string, DetailInfo> InfoMap = new Dictionary <string, DetailInfo>();

            //buttonList[0].Click();
            sizeButton.Click();
            Thread.Sleep(2000);

            var buttonListHead = _driver.FindElement(By.XPath("//ul[@class='select_list']"));
            var buttonListCnt  = buttonListHead.FindElements(By.XPath("//*[contains(@class,'select_item')]")).Count;
            var buttonList     = buttonListHead.FindElements(By.XPath("//*[contains(@class,'select_item')]"));

            buttonList[0].FindElement(By.TagName("button")).Click();
            Thread.Sleep(1000);

            for (int i = 1; i < buttonListCnt; i++)
            {
                sizeButton.Click();
                Thread.Sleep(2000);

                buttonList = _driver.FindElement(By.XPath("//ul[@class='select_list']")).FindElements(By.XPath("//*[contains(@class,'select_item')]"));
                string[] size = buttonList[i].FindElement(By.ClassName("size")).Text.Split('(');
                buttonList[i].FindElement(By.TagName("button")).Click();
                Thread.Sleep(2000);

                string latestSalePrc = _driver.FindElement(By.XPath("//*[contains(@class,'detail_price')]")).FindElement(By.ClassName("num")).Text;
                if (latestSalePrc.Equals("-"))
                {
                    latestSalePrc = "0";
                }
                string price = _driver.FindElements(By.XPath("//*[contains(@class,'btn_division')]"))[1].FindElement(By.ClassName("num")).Text;

                string usSize = krUsSizeMap[size[0]];

                /*
                 * if (size.Length > 1)
                 * {
                 *  usSize = Regex.Replace(size[1], @"\D", "");
                 * }*/
                if (!price.Equals("-"))
                {
                    if (InfoMap.ContainsKey(usSize))
                    {
                        InfoMap[usSize] = new DetailInfo()
                        {
                            krSize = size[0], usSize = usSize, kreamKrPrice = float.Parse(price), kreamLatestKrPrice = float.Parse(latestSalePrc)
                        };
                    }
                    else
                    {
                        InfoMap.Add(usSize, new DetailInfo()
                        {
                            krSize = size[0], usSize = usSize, kreamKrPrice = float.Parse(price), kreamLatestKrPrice = float.Parse(latestSalePrc)
                        });
                    }
                }
            }

            Thread.Sleep(3000);
            _driver.Quit();

            return(InfoMap);
        }
예제 #6
0
        public void Test1()
        {
            Workbook   wb     = new Workbook("DeltaHRMS_StatusReport.xlsx");
            Worksheet  sheet  = wb.Worksheets[0];
            IWebDriver driver = new ChromeDriver();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
            Cell   cell;
            string d;

            String[] B = { "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "B10", "B11", "B12", "B13", "B14" };
            string[] C = { "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C11", "C12", "C13", "C14" };
            String[] D = { "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", "D11", "D12", "D13", "D14" };

            for (int i = 0; i <= 12; i++)
            {
                string ValueB = B[i];
                string ValueC = C[i];
                string ValueD = D[i];
                cell = sheet.Cells[ValueB];
                string TestStep = cell.Value.ToString();
                try
                {
                    switch (ValueB)
                    {
                    case "B2":
                        if (TestStep.Contains("Browser"))
                        {
                            driver.Navigate().GoToUrl("https://www.google.com/");
                            driver.Manage().Window.Maximize();
                            if (driver.Url.Contains("google"))
                            {
                                cell = sheet.Cells[ValueC];
                                cell.PutValue("Pass");
                            }
                        }
                        break;

                    case "B3":
                        if (TestStep.Contains("HRMS"))
                        {
                            driver.Navigate().GoToUrl("http://deltahrmsqa.deltaintech.com/");
                            if (driver.Url.Contains("deltaintech.com"))
                            {
                                cell = sheet.Cells[ValueC];
                                cell.PutValue("Pass");
                            }
                        }
                        break;

                    case "B4":
                        if (TestStep.Contains("Login"))
                        {
                            XmlDocument xDoc = new XmlDocument();
                            xDoc.Load("LoginDetails.Xml");
                            string UserName = xDoc.DocumentElement.SelectSingleNode("UserName").InnerText;
                            string Password = xDoc.DocumentElement.SelectSingleNode("Password").InnerText;
                            SetMethods.EnterText(driver, "username", UserName, "Id");
                            SetMethods.EnterText(driver, "password", Password, "Id");
                            SetMethods.Click(driver, "loginsubmit", "Id");
                            if (driver.Url.Contains("welcome"))
                            {
                                cell = sheet.Cells[ValueC];
                                cell.PutValue("Pass");
                            }
                        }
                        break;

                    case "B5":
                        if (TestStep.Contains("Services"))
                        {
                            SetMethods.Click(driver, "thumbnail_4", "Id");
                            if (driver.Url.Contains("welcome"))
                            {
                                cell = sheet.Cells[ValueC];
                                cell.PutValue("Pass");
                            }
                        }
                        break;

                    case "B6":
                        if (TestStep.Contains("Leaves"))
                        {
                            SetMethods.Click(driver, "acc_li_toggle_31", "Id");
                            if (driver.Url.Contains("welcome"))
                            {
                                cell = sheet.Cells[ValueC];
                                cell.PutValue("Pass");
                            }
                        }
                        break;

                    //case "B7":
                    //    if (TestStep.Contains("Request"))
                    //    {
                    //        SetMethods.Click(driver, "Leave Request", "LinkText");
                    //        if (driver.Url.Contains("leaverequest"))
                    //        {
                    //            cell = sheet.Cells[ValueC];
                    //            cell.PutValue("Pass");
                    //        }

                    //    }
                    //    break;

                    //case "B8":
                    //    if (TestStep.Contains("Apply"))
                    //    {
                    //        SetMethods.Click(driver, "//input[@value='Apply Leave']", "XPath");
                    //        if (driver.Url.Contains("leaverequest"))
                    //        {
                    //            cell = sheet.Cells[ValueC];
                    //            cell.PutValue("Pass");
                    //        }

                    //    }
                    //    break;

                    //case "B9":
                    //    if (TestStep.Contains("type"))
                    //    {
                    //        SetMethods.Click(driver, "//span[text()='Select Leave Type']", "XPath");
                    //        SetMethods.Click(driver, "//span[contains(text(),'Earned Leave ')]", "XPath");
                    //        if (driver.Url.Contains("leaverequest"))
                    //        {
                    //            cell = sheet.Cells[ValueC];
                    //            cell.PutValue("Pass");


                    //        }
                    //    }
                    //    break;

                    //case "B10":
                    //    if (TestStep.Contains("From"))
                    //    {
                    //        SetMethods.Click(driver, "//input[@id='from_date']", "XPath");
                    //        var days = driver.FindElements(By.CssSelector("a[class='ui-state-default']"));
                    //        var builder = new Actions(driver);
                    //        builder.Click(days[13]).Build().Perform();
                    //        if (driver.Url.Contains("leaverequest"))
                    //        {
                    //            cell = sheet.Cells[ValueC];
                    //            cell.PutValue("Pass");
                    //        }

                    //    }
                    //    break;

                    //case "B11":
                    //    if (TestStep.Contains("To"))
                    //    {
                    //        SetMethods.Click(driver, "//input[@id='to_date']", "XPath");
                    //        SetMethods.Click(driver, "a[class='ui-state-default']", "CssSelector");
                    //        SetMethods.Click(driver, "//input[@id='to_date']", "XPath");
                    //        var days = driver.FindElements(By.CssSelector("a[class='ui-state-default']"));
                    //        var builder = new Actions(driver);
                    //        builder.Click(days[2]).Build().Perform();
                    //        if (driver.Url.Contains("leaverequest"))
                    //        {
                    //            cell = sheet.Cells[ValueC];
                    //            cell.PutValue("Pass");

                    //        }

                    //    }

                    //    break;

                    //case "B12":
                    //    if (TestStep.Contains("Reason"))
                    //    {
                    //        SetMethods.EnterText(driver, "reason", "Personal Work", "Id");
                    //        if (driver.Url.Contains("leaverequest"))
                    //        {

                    //            cell = sheet.Cells[ValueC];
                    //            cell.PutValue("Pass");

                    //        }

                    //    }
                    //    break;

                    //case "B13":
                    //    if (TestStep.Contains("Apply"))
                    //    {

                    //        SetMethods.Click(driver, "submit", "Name");
                    //        cell = sheet.Cells[ValueC];
                    //        cell.PutValue("Pass");
                    //        Thread.Sleep(10000);

                    //    }
                    //    break;


                    case "B14":
                        if (TestStep.Contains("Allocated"))
                        {
                            SetMethods.Click(driver, "//div[contains(@class,'side-menu')]//li//a[@id='62']", "XPath");
                            SetMethods.Click(driver, "filter_all", "Id");
                            SetMethods.SelectDropdown(driver, "perpage_pendingleaves", "100", "Id");
                            Thread.Sleep(3000);


                            IList <IWebElement> rows = driver.FindElements(By.XPath("//table[@class='grid']/tbody/tr"));
                            int    NumberOfRows      = rows.Count();
                            String FirstPath         = "//*[@id='pendingleaves']/table/tbody/tr[";
                            String SecondPath        = "]/td[6]/span";
                            double Sum = 0;

                            for (int k = 2; k < NumberOfRows; i++)
                            {
                                string innerText = driver.FindElement(By.XPath(FirstPath + k + SecondPath)).Text;
                                Double Days      = Convert.ToDouble(innerText);
                                Sum += Days;
                            }
                            cell = sheet.Cells["C14"];
                            cell.PutValue(Sum);
                        }

                        break;
                    }
                }
                catch (Exception e)
                {
                    cell = sheet.Cells["E2"];
                    cell.PutValue("Fail");
                    cell = sheet.Cells[ValueC];
                    cell.PutValue("Fail");
                    driver.Quit();
                    throw e;
                }
                finally
                {
                    d    = DateTime.Now.ToString();
                    cell = sheet.Cells[ValueD];
                    cell.PutValue(d);
                    wb.Save("DeltaHRMS_StatusReport_Updated.Xlsx", SaveFormat.Xlsx);
                }
            }
            driver.Quit();
        }
예제 #7
0
        static void Takip()
        {
            IWebDriver driver = new ChromeDriver();

            Console.WriteLine("Kullanıcı adını girin :");
            string kullanici = Console.ReadLine();

            driver.Navigate().GoToUrl("https://www.instagram.com/" + kullanici + "/following/");

            System.Threading.Thread.Sleep(3000);

            driver.FindElement(By.Name("username")).SendKeys("*****@*****.**");
            System.Threading.Thread.Sleep(2000);


            System.Threading.Thread.Sleep(1000);

            driver.FindElement(By.Name("password")).SendKeys("886179");
            System.Threading.Thread.Sleep(1000);
            driver.FindElement(By.Name("password")).Submit();

            System.Threading.Thread.Sleep(1000);

            System.Threading.Thread.Sleep(4000);

            var donenSayi = TakipciSayi(driver);

            string textt;


            double donenSayi1 = 0;


            int sayac = 0;
            var icon  = driver.FindElements(By.XPath("//*[@id=\"react-root\"]/section/main/div/header/section/ul/li/a"));

            foreach (IWebElement element in icon)
            {
                var text = element.Text;
                if (element.Text != (donenSayi.ToString() + " takipçi"))
                {
                    textt = driver
                            .FindElements(By.XPath("//*[@id=\"react-root\"]/section/main/div/header/section/ul/li/a/span"))[sayac].Text;
                    donenSayi1 = Convert.ToDouble(textt);

                    IWebElement page =
                        driver.FindElements(By.XPath("//*[@id=\"react-root\"]/section/main/div/header/section/ul/li/a"))[sayac];
                    page.Click();
                }

                sayac++;
            }

            double donenSayi2 = donenSayi1;



            System.Threading.Thread.Sleep(2000);


            System.Threading.Thread.Sleep(2000);



            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;

            System.Threading.Thread.Sleep(1000);

            double count = 0;

            while (donenSayi2 != count)
            {
                js.ExecuteScript("var followers = document.querySelector(\".isgrP\"); " +
                                 "followers.scrollBy(0,600);");
                System.Threading.Thread.Sleep(1000);
                count = driver.FindElements(By.XPath("/html/body/div/div/div/ul/div/li")).Count;

                System.Threading.Thread.Sleep(1000);
            }

            System.Threading.Thread.Sleep(2000);

            System.Threading.Thread.Sleep(2000);


            IReadOnlyCollection <IWebElement> searchResult =
                driver.FindElements(By.XPath("//a[@class='FPmhX notranslate  _0imsa ']"));


            foreach (var search in searchResult)
            {
                var t = search.Text;
                Console.WriteLine(t);
                VeriYazTakipci(t, "Takip", kullanici);
            }
        }
예제 #8
0
        protected override ReadOnlyCollection <IWebElement> GetProductList(ChromeDriver driver)
        {
            var list = driver.FindElements(By.CssSelector("tr.productListing"));

            return(list);
        }
예제 #9
0
        static void Main(string[] args)
        {
            ChromeOptions options = new ChromeOptions();

            options.AddArgument("--start-maximized");

            using (var driver = new ChromeDriver(options))
            {
                driver.Navigate().GoToUrl("https://staff.edoctor.io/");

                var loginButton = driver.FindElementById("loginByeDoctorEmail");

                loginButton.Click();
                driver.SwitchTo().Window(driver.WindowHandles[1]);

                LoginGmail(driver, "*****@*****.**", "minh130107");

                driver.SwitchTo().Window(driver.WindowHandles[0]);

                (new WebDriverWait(driver, TimeSpan.FromSeconds(10)))
                .Until(ExpectedConditions.ElementToBeClickable(By.PartialLinkText("Vận hành")));

                driver.FindElement(By.PartialLinkText("Vận hành")).Click();

                (new WebDriverWait(driver, TimeSpan.FromSeconds(10)))
                .Until(ExpectedConditions.ElementToBeClickable(By.PartialLinkText("Đơn tôi triển khai")));

                driver.FindElement(By.PartialLinkText("Đơn tôi triển khai")).Click();

                (new WebDriverWait(driver, TimeSpan.FromSeconds(10)))
                .Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[text()='Tất cả thời gian']")));

                driver.FindElements(By.XPath("//button[text()='Tất cả thời gian']"))[1].Click();

                driver.FindElements(By.XPath("//li[@data-range-key='Ngày mai' or text()='Ngày mai']"))[1].Click();

                var patientInfo = driver.FindElements(By.XPath("//table//div[@class='patient-info']"));

                foreach (var pInfo in patientInfo)
                {
                    var name = pInfo.FindElement(By.ClassName("text-strong mb-1")).Text;

                    Console.WriteLine("name: " + name);

                    var tagpInfo = pInfo.FindElements(By.XPath("p"));

                    var phoneNumber = tagpInfo[0].FindElement(By.TagName("a")).Text;

                    if (tagpInfo.Count < 6)
                    {
                    }
                    else
                    {
                    }
                }


                Console.ReadKey();

                //driver.GetScreenshot().SaveAsFile(@"screen.png", OpenQA.Selenium.ScreenshotImageFormat.Png);
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            {
                var driver = new ChromeDriver(Environment.CurrentDirectory);
                //Console.WriteLine("TEST!");
                //driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(3);
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
                driver.Navigate().GoToUrl("https://finance.yahoo.com/");
                wait.Until(ExpectedConditions.ElementExists(By.Id("uh-signedin")));

                driver.FindElement(By.XPath(".//a[@id = 'uh-signedin']")).Click();


                Console.WriteLine("Email:");
                var userName = Console.ReadLine();

                driver.FindElement(By.XPath(".//input[@name = 'username']")).SendKeys(userName);

                driver.FindElement(By.XPath(".//input[@id= 'login-signin']")).Click();

                Console.WriteLine("Password:"******".//input[@id = 'login-passwd']")).SendKeys(passWord);
                driver.FindElement(By.XPath(".//button[@id = 'login-signin']")).Click();

                // Navigate to My portfolio page
                driver.FindElement(By.XPath(".//a[@title = 'My Portfolio']")).Click();

                // Wit for pop up, then click 'x' to exit pop up
                wait.Until(ExpectedConditions.ElementExists(By.XPath("//dialog[@id = '__dialog']/section/button")));
                driver.FindElement(By.XPath("//dialog[@id = '__dialog']/section/button")).Click();

                // Click on watch list under Portfolio
                driver.FindElement(By.XPath("//*[@id=\"main\"]/section/section/div[2]/table/tbody/tr[1]/td[1]/a")).Click();


                // Ready to scrape data to console
                wait.Until(ExpectedConditions.ElementExists(By.XPath("//html[1]/body[1]/div[2]/div[3]/section[1]/section[2]/div[2]/table[1]/tbody[1]")));
                var table    = driver.FindElement(By.XPath("/html[1]/body[1]/div[2]/div[3]/section[1]/section[2]/div[2]/table[1]/tbody[1]"));
                var children = table.FindElements(By.XPath(".//*"));
                //Console.WriteLine(table);

                List <IWebElement> elements = new List <IWebElement>();
                elements = driver.FindElements(By.XPath("//tbody/tr")).ToList <IWebElement>();


                List <Stock> PortStocks = new List <Stock>();

                foreach (var stock in elements)
                {
                    var      newStock     = Convert.ToString(stock.Text);
                    string[] anotherStock = newStock.Split(' ');
                    //foreach(var item in anotherStock)
                    //{
                    //    Console.WriteLine(item);
                    //}
                    PortStocks.Add(new Stock()
                    {
                        StockSymbol = anotherStock[0], LastPrice = anotherStock[1],
                        MarketTime  = "0" + anotherStock[5] + ":00",
                        PriceChange = anotherStock[2], PercentChange = anotherStock[3]
                    });
                }

                foreach (var stock in PortStocks)
                {
                    Console.WriteLine(stock.StockSymbol);
                    Console.WriteLine(stock.LastPrice);
                    Console.WriteLine(stock.MarketTime);
                    Console.WriteLine(stock.PriceChange);
                    Console.WriteLine(stock.PercentChange);
                }



                // Set Up Local Database
                var connString = "Host=localhost;Username=urbensonlaurent;Password=davidbabo16;Database=teststocks";

                using (var connect = new NpgsqlConnection(connString))
                {
                    connect.Open();

                    // Insert some data
                    using (var cmd = new NpgsqlCommand())
                    {
                        cmd.Connection = connect;
                        foreach (var stock in PortStocks)
                        {
                            string data = string.Format("INSERT INTO stockington (SYMBOL, LASTPRICE, CHANGE, DATETIME) VALUES ('{0}','{1}',{2},'{3}')", stock.StockSymbol, stock.LastPrice, stock.PriceChange, stock.MarketTime);
                            cmd.CommandText = data;
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
예제 #11
0
        public static void ViaIndeed(string searchTerm, string location, string countryCode, bool companySingleApply, string sql, User user, string apikey)
        {
            SqlConnection con = new SqlConnection(sql);

            // Append string with rest of display
            display = "Location: " + location + " Search Term(s): " + searchTerm;

            Console.Clear();
            // Retrieve all pages with "Quick Apply" button on them ONLY
            var supersetQuickies = GetAllQuickies(searchTerm, location, countryCode, apikey);

            Console.Clear();
            Console.WriteLine(display);

            // Reduce by configurations passed. Do not appy to
            // same company 2ce in a session (companySingleApply)
            var reducedQuckies = ReduceQuickies(supersetQuickies, companySingleApply, con);

            //There is nothing (new) to add therefore exit
            if (reducedQuckies.Count == 0)
            {
                return;
            }

            // Initialize Chrome Driver with Selenium API
            var driver = new ChromeDriver();

            for (int j = 0; j < reducedQuckies.Count; j++)
            {
                // If already applied to company proceed loop
                if (IndeedSql.AlreadyAppliedCompany(reducedQuckies[j].Company, con))
                {
                    continue;
                }

                //Load the Job Posting page
                driver.Url = reducedQuckies[j].Url;

                string jk       = reducedQuckies[j].Jobkey;   // Passed from Indeed API query
                string jobTitle = reducedQuckies[j].JobTitle; // Passed from Indeed API query
                string hl       = "en";                       // English parameter
                string co       = countryCode;

                //Get Variables to Store later from Job Posting page directly:
                string jobCompany = driver.FindElementByClassName("company").Text;
                string jobId      = "";
                try
                {
                    jobId = driver.FindElements
                                (By.CssSelector(".indeed-apply-widget"))[0]
                            .GetAttribute("data-indeed-apply-jobid");
                }
                catch { continue; }

                string apiToken =
                    driver.FindElements(By.CssSelector(".indeed-apply-widget"))[0].GetAttribute(
                        "data-indeed-apply-apitoken");
                string postUrl =
                    driver.FindElements(By.CssSelector(".indeed-apply-widget"))[0].GetAttribute(
                        "data-indeed-apply-posturl");
                string jobUrl =
                    driver.FindElements(By.CssSelector(".indeed-apply-widget"))[0].GetAttribute(
                        "data-indeed-apply-joburl");
                string iaUid =
                    driver.FindElement(By.Id("indeed-apply-js"))
                    .GetAttribute("data-indeed-apply-qs")
                    .Replace("vjtk=", "");     //iaUid == vjtk (variable)!!!!!!
                string advNum =
                    driver.FindElements(By.CssSelector(".indeed-apply-widget"))[0].GetAttribute(
                        "data-indeed-apply-advnum");

                string email = string.Empty;

                try
                {
                    email =
                        driver.FindElements(By.CssSelector(".indeed-apply-widget"))[0].GetAttribute(
                            "data-indeed-apply-email");
                }
                catch {}

                // Generate URL is for the Application page ONLY
                string applyUrl = GenerateURL.ApplyUrl(email, postUrl, jk, jobTitle, jobUrl, jobCompany,
                                                       jobId, apiToken, co, hl, advNum, iaUid);

                // Cover Letter Construction
                string pathToTemplate = user.CoverLetter; // Path to cover letter template.

                // Location of template
                string coverLetter = File.ReadAllText(pathToTemplate);

                // Simple replace to insert Location on the Fly (e.g. Richmond, VA)
                coverLetter = coverLetter.Replace("%varArea%", reducedQuckies[j].FormattedLocationFull);

                // Simple replace to insert Position on the Fly
                coverLetter = coverLetter.Replace("%varPos%", reducedQuckies[j].JobTitle);

                // Simple replace to insert Company Name (e.g. Bit Byte Buffer, LLC)
                coverLetter = coverLetter.Replace("%varCompany%", reducedQuckies[j].Company);

                // Workaround because driver will crash if you use for too long.
                // This may be resolved with newer versions of the driver
                count++;
                if (count == 10)
                {
                    count = 0;
                    driver.Close();
                    driver     = new ChromeDriver();
                    driver.Url = reducedQuckies[j].Url; //Information Page
                }

                // Navigate to Application Page
                driver.Url = applyUrl;

                // Fill in My Name
                try // 1st Potential Id
                {
                    driver.FindElementById("applicant.name").Clear();
                    driver.FindElementById("applicant.name").SendKeys(user.AppName);
                }
                catch
                {
                    try // 2nd Potential Id (prefixed with "input-")
                    {
                        driver.FindElementById("input-applicant.name").Clear();
                        driver.FindElementById("input-applicant.name").SendKeys(user.AppName);
                    }
                    catch
                    {
                        // Can't insert name, therefore must not be a
                        // quick apply (otherwise run should go smoothly)
                        continue;
                    }
                }

                // Fill in My Email
                try // 1st Potential Id
                {
                    driver.FindElementById("applicant.email").Clear();
                    driver.FindElementById("applicant.email").SendKeys(user.AppEmail);
                }
                catch
                {
                    try // 2nd Potential Id (prefixed with "input-")
                    {
                        driver.FindElementById("input-applicant.email").Clear();
                        driver.FindElementById("input-applicant.email").SendKeys(user.AppEmail);
                    }
                    catch
                    {
                        continue;
                    }
                }

                // Fill in Phone Number
                try // 1st Potential Id
                {
                    driver.FindElementById("applicant.phoneNumber").Clear();
                    driver.FindElementById("applicant.phoneNumber").SendKeys(user.AppPhone);
                }
                catch
                {
                    try // 2nd Potential Id (prefixed with "input-")
                    {
                        driver.FindElementById("input-applicant.phoneNumber").Clear();
                        driver.FindElementById("input-applicant.phoneNumber").SendKeys(user.AppPhone);
                    }
                    catch
                    {
                        continue;
                    }
                }

                //Upload Resume
                try
                {
                    driver.FindElementById("resume")
                    .SendKeys(user.AppResumePath);
                }
                catch
                {
                    try
                    {
                        driver.FindElementById("ia-FilePicker-resume")
                        .SendKeys(user.AppResumePath);
                    }
                    catch
                    {
                        continue;
                    }
                }

                //Upload Supporting documents (e.g. Degree, Certifications, etc.)
                try
                {
                    if (!string.IsNullOrEmpty(user.AppSupportingDoc1))
                    {
                        driver.FindElementById("multattach1")
                        .SendKeys(user.AppSupportingDoc1);
                    }

                    if (!string.IsNullOrEmpty(user.AppSupportingDoc2))
                    {
                        driver.FindElementById("multattach2")
                        .SendKeys(user.AppSupportingDoc2);
                    }

                    if (!string.IsNullOrEmpty(user.AppSupportingDoc3))
                    {
                        driver.FindElementById("multattach3")
                        .SendKeys(user.AppSupportingDoc3);
                    }

                    if (!string.IsNullOrEmpty(user.AppSupportingDoc4))
                    {
                        driver.FindElementById("multattach4")
                        .SendKeys(user.AppSupportingDoc4);
                    }

                    if (!string.IsNullOrEmpty(user.AppSupportingDoc5))
                    {
                        driver.FindElementById("multattach5")
                        .SendKeys(user.AppSupportingDoc5);
                    }
                }
                catch
                {
                    // stub: means there is no control for
                    // supporting file uploads on page which is common
                }

                try
                {
                    // Fill cover letter text box on form (attempt 1 with original Id)

                    IJavaScriptExecutor js = driver;
                    js.ExecuteScript("document.getElementById('applicant.applicationMessage').setAttribute('style', '')");
                    driver.FindElementById("applicant.applicationMessage").Click();
                    driver.FindElementById("applicant.applicationMessage").Clear();
                    driver.FindElementById("applicant.applicationMessage").SendKeys(coverLetter);
                }
                catch
                {
                    try
                    {
                        // Fill cover letter text box on form (attempt 2 with new preixed "textarea-" Id)

                        IJavaScriptExecutor js = driver;
                        js.ExecuteScript("document.getElementById('textarea-applicant.applicationMessage').setAttribute('style', '')");
                        driver.FindElementById("textarea-applicant.applicationMessage").Click();
                        driver.FindElementById("textarea-applicant.applicationMessage").Clear();
                        driver.FindElementById("textarea-applicant.applicationMessage").SendKeys(coverLetter);
                    }
                    catch
                    {
                        // Could not identify an Application Message textbox to fill
                        continue;
                    }
                }
                //************ Apply Here *************

                //Click on button submit

                try // Attempt 1, click button by CSS Class Selector
                {
                    driver.FindElement(By.CssSelector(".button_content")).Click();
                }
                catch
                {
                    try // Attempt 2, click button by CSS ID Selector
                    {
                        driver.FindElement(By.CssSelector("#form-action-submit")).Click();
                    }
                    catch
                    {
                        // Stub: Cannot find Application Button
                        continue;
                    }
                }

                // Let new page load for 1.5 seconds after clicking
                // submit application button
                Thread.Sleep(1500);

                try // Additional Yes/No questions added to US applications sometimes
                {
                    driver.FindElement(By.Id("q_0")).SendKeys("Yes");
                    driver.FindElement(By.Id("apply")).Click();
                }
                catch
                {
                    // Stub: Not uncommon for this not to exist. In most cases it does not exist.
                }

                // Start Save process
                Stopwatch sw = new Stopwatch();
                sw.Start();

                while (true)
                {
                    try
                    {
                        //Give it 2.5 minutes to upload all documents as max time permissible
                        if (sw.ElapsedMilliseconds > 60000 * 2.5)
                        {
                            // Insert Failure message here!!
                            SaveSubmission(reducedQuckies[j], false, con); //Changed to true as they are fine.
                            Console.Clear();
                            Console.WriteLine(display);
                            Console.WriteLine("\nFailed to apply: " + reducedQuckies[j].Company + " (" + reducedQuckies[j].JobTitle + ")");
                            break; // Exit while loop
                        }

                        driver.FindElement(By.Id("ia_success"));
                        //Insert success message here!!
                        Console.Clear();
                        Console.WriteLine(display);
                        Console.WriteLine("\nSucceeded in applying to: " + reducedQuckies[j].Company + " (" + reducedQuckies[j].JobTitle + ")");
                        SaveSubmission(reducedQuckies[j], true, con);
                        break;
                    }
                    catch
                    {
                        // Stub: recursion occurs until element found on page
                        // and save is successful, or element is not found after
                        // 2.5 minutes and record is saved as unsuccessful application
                    }
                }

                // Sleep for 2 seconds before moving to next application
                Thread.Sleep(2000);
            }

            driver.Close();
            driver.Dispose();
        }
예제 #12
0
        static void Main(string[] args)
        {
            using (var driver = new ChromeDriver())
            {
                /* Initialization */


                string projectTitle  = ""; // Project Name
                string firstStepName = "InternalReview";

                Console.WriteLine("Hi, please chose TMS project name: \n" +
                                  "1) Porsche BAL 2.0 \n" +
                                  "2) Porsche Cosima");

                int projectChose = Int32.Parse(Console.ReadLine());

                switch (projectChose)
                {
                case 1:
                    projectTitle = "Porsche BAL 2.0";
                    break;

                case 2:
                    projectTitle = "Porsche Cosima";
                    break;

                default:
                    System.Environment.Exit(1);
                    break;
                }

                Console.WriteLine("Now, please chose TMS setting name: \n" +
                                  "1) Internal Review; " +
                                  "2) Editing");

                int settingChose = Int32.Parse(Console.ReadLine());

                switch (settingChose)
                {
                case 1:
                    firstStepName = "InternalReview";
                    break;

                case 2:
                    firstStepName = "Editing";
                    break;

                default:
                    System.Environment.Exit(1);
                    break;
                }

                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));

                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("https://tms.lionbridge.com/");

                ProjectsPage testPage = new ProjectsPage(driver, projectTitle);

                testPage.ClickChosenProject();
                ParticularProjectPage testProjectPage = new ParticularProjectPage(driver);

                testProjectPage.ProfileClick(driver);
                testProjectPage.ChangeItemsPerPageMin(driver);

                testProjectPage.StatusClick(driver);
                StatusPage testStatusPage = new StatusPage(driver);

                testStatusPage.AssigneesClick(driver);
                AssigneesPage porscheAssigneesPage = new AssigneesPage(driver);

                if (porscheAssigneesPage.ChosenActivityClick(driver, firstStepName) != 1)
                {
                    Console.WriteLine("There is no {0} steps!", firstStepName);
                    return;
                }
                porscheAssigneesPage = new AssigneesPage(driver);

                PageBar testPageBar = new PageBar(driver);
                testPageBar.ItemsPerPageSetMaximalValue(driver);

                AssigneesAndJobs asob = new AssigneesAndJobs(driver);

                List <StatusAssigneeInfo> listOfStatusAssgineeInfo = new List <StatusAssigneeInfo>();
                StatusAssigneeInfo        auxiliary;

                foreach (var ass in asob.assigneesJobsList)
                {
                    Console.WriteLine(ass.GetJobsName);
                }


                foreach (Assignee ass in asob.assigneesList)
                {
                    for (int i = 0; i < ass.GetAssingeeJobsNumberInt; i++)
                    {
                        auxiliary = new StatusAssigneeInfo(ass, asob.assigneesJobsList.ElementAt(i));
                        listOfStatusAssgineeInfo.Add(auxiliary);
                    }
                    for (int i = 0; i < ass.GetAssingeeJobsNumberInt; i++)
                    {
                        asob.assigneesJobsList.RemoveAt(0);
                    }

                    Console.WriteLine(ass.GetAssigneeName + " " + ass.GetAssingeeJobsNumberInt);
                }

                foreach (var ass in listOfStatusAssgineeInfo)
                {
                    Console.WriteLine(ass.jobName + " " + ass.reviewerName + " " + ass.sourceLanguage);
                }

                asob = new AssigneesAndJobs(driver);
                asob.TagMultipleJobs(driver, 0, asob.GetAssigneeJobsListSize - 1);

                ViewsMenu assigneesViewsMenu = new ViewsMenu(driver);
                assigneesViewsMenu.JobsView.ButtonClick();

                JobsSectionJobs jsj = new JobsSectionJobs(driver);
                jsj.jobsPageBar.ItemsPerPageSetMaximalValue(driver);

                jsj = new JobsSectionJobs(driver);

                IReadOnlyCollection <IWebElement> auxiliaryCollection;
                ResultJob   auxiliaryJobs = new ResultJob();
                IWebElement jobsResultsContainer;

                IJavaScriptExecutor jse;

                string path = Path.Combine(Directory.GetCurrentDirectory(), "TestFile.csv");

                using (StreamWriter sw = new StreamWriter(path))
                {
                    string[] values1 = { "Job Name", "Reviewer Name", "Translator Name", "Source Language", "Target Language", "Effort", "Wordcount" };
                    string   line1   = String.Join(";", values1);

                    sw.WriteLine(line1);

                    foreach (var info in listOfStatusAssgineeInfo)
                    {
                        jse = (IJavaScriptExecutor)driver;
                        jse.ExecuteScript("arguments[0].scrollIntoView();", jsj.GetJobElement(driver, info.jobName));

                        jsj.ShowHistoryOfJob(driver, info.jobName);

                        JobHistoryFilter filter = new JobHistoryFilter(driver);

                        filter.FiltersPanelInitialization(driver);
                        filter.ChosenActivityClick(driver, "Translation");

                        filter = new JobHistoryFilter(driver);
                        filter.FiltersPanelInitialization(driver);

                        filter.SourceLanguageFilterClick(driver);
                        filter.ChosenSourceLanguageClick(driver, info.sourceLanguage);

                        filter = new JobHistoryFilter(driver);
                        filter.FiltersPanelInitialization(driver);

                        filter.TargetLanguageFilterClick(driver);
                        filter.ChosenTargetLanguageClick(driver, info.targetLanguage);

                        wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("r_L")));
                        auxiliaryCollection = driver.FindElements(By.Id("pup_avw"));

                        jobsResultsContainer = auxiliaryCollection.ElementAt(0);

                        auxiliaryCollection = jobsResultsContainer.FindElements(By.ClassName("r_L"));
                        auxiliaryJobs       = new ResultJob(auxiliaryCollection.ElementAt(0));

                        listOfStatusAssgineeInfo.ElementAt(listOfStatusAssgineeInfo.IndexOf(info)).TranslatorName = auxiliaryJobs.GetTranlatorName;

                        PopUpBody popuPBody = new PopUpBody(driver);
                        popuPBody.CloseButtonClick(driver);

                        string[] values = { info.jobName, info.reviewerName, info.translatorName, info.sourceLanguage, info.targetLanguage, info.effort, info.wordcount };
                        string   line   = String.Join(";", values);

                        sw.WriteLine(line);
                    }

                    sw.Flush();
                }


                // iterates over the users
                //foreach (var info in listOfStatusAssgineeInfo)
                //   {
                // creates an array of the user's values
                //  string[] values = { info.jobName, info.reviewerName, info.translatorName, info.sourceLanguage, info.targetLanguage };
                // creates a new line
                //   string line = String.Join(";", values);
                // writes the line
                // sw.WriteLine(line);
                //  }
                // flushes the buffer
                // sw.Flush();
                //  }
            }
        }
        //Weight calculation thread
        private void CalcWeightThread(string _blockInfoPath, string _saveInfoPath, float _assumedWeight = 0.5f, float _percentSim = 50f)
        {
            Dictionary <string, string> blockInfo = new Dictionary <string, string>();
            string line;
            int    blockTypeCount = 0;
            int    blockCount     = 0;

            ChangeCtrlText(this, string.Format("{0} - Getting project information - Block Types: {1} - Blocks: {2}", ogTitle, blockTypeCount, blockCount));

            StreamReader blockInfoFile = new StreamReader(_blockInfoPath);

            while ((line = blockInfoFile.ReadLine()) != null)
            {
                string[] info = line.Split('|');
                blockInfo.Add(info[0].Trim(), info[1].Trim());
                blockCount += int.Parse(info[1].Trim());
                blockTypeCount++;
                ChangeCtrlText(this, string.Format("{0} - Getting project information - Block Types: {1} - Blocks: {2}", ogTitle, blockTypeCount, blockCount));
            }

            ChangeCtrlText(this, string.Format("{0} - Navigating to \'www.bricklinks.com\'", ogTitle));
            ChromeDriver chromeDriver = new ChromeDriver();

            chromeDriver.Navigate().GoToUrl("https://www.bricklink.com");

            ChangeCtrlText(this, string.Format("{0} - Gathering weight information for project", ogTitle));

            int   curBlockTypeCount = 0;
            int   curBlockCount     = 0;
            float currentWeight     = 0f;
            Dictionary <string, string> weightInfo = new Dictionary <string, string>();

            blockInfoFile.Close();

            foreach (KeyValuePair <string, string> block in blockInfo)
            {
                try
                {
                    IWebElement cookiesElem = chromeDriver.FindElement(By.CssSelector("[class='bl-btn primaryBlue text--bold l-margin-right']"));
                    cookiesElem.Click();
                }catch { }
                float blockWeight = 0;
                ChangeCtrlText(this, string.Format("{0} - Gathering weight information for project - Block Types: {1}/{2} - Blocks: {3}/{4} - Project Weight: {5}g", ogTitle, curBlockTypeCount, blockTypeCount, curBlockCount, blockCount, currentWeight));

                chromeDriver.Navigate().GoToUrl(string.Format("https://www.bricklink.com/v2/search.page?q={0}", block.Key));

                bool loop = true;
                while (loop)
                {
                    IWebElement elem = chromeDriver.FindElement(By.Id("_idSelSortType"));
                    if (elem != null && elem.Displayed && elem.Enabled)
                    {
                        loop = false;
                    }
                    else
                    {
                        IList <IWebElement> elemList = chromeDriver.FindElements(By.ClassName("links"));
                        foreach (IWebElement temp in elemList)
                        {
                            if (temp.Text == "How to Find Items")
                            {
                                if (temp.Displayed && temp.Enabled)
                                {
                                    loop = false;
                                }
                            }
                        }
                    }
                }

                try
                {
                    IList <IWebElement> itemListElem = chromeDriver.FindElements(By.ClassName("pspItemNameLink"));
                    int    count           = 0;
                    string newBlockName    = block.Key.ToLower().Replace(" ", "");
                    int    newBlockNameLen = newBlockName.Length;
                    while (count < itemListElem.Count)
                    {
                        try
                        {
                            itemListElem[count].Click();
                        }
                        catch
                        {
                            count++;
                        }
                    }

                    string tempWeightInfo = chromeDriver.FindElement(By.Id("item-weight-info")).Text;

                    if (!tempWeightInfo.Contains("?"))
                    {
                        blockWeight = float.Parse(tempWeightInfo.Replace("g", ""));
                    }
                    else
                    {
                        blockWeight = _assumedWeight;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: " + e.Message);
                    blockWeight = _assumedWeight;
                }

                currentWeight += blockWeight * float.Parse(block.Value);
                weightInfo.Add(block.Key, blockWeight.ToString() + "g");
                curBlockTypeCount++;
                curBlockCount += int.Parse(block.Value);
            }

            ChangeCtrlText(this, string.Format("{0} - Finished calculating weight of project - Block Types: {1}/{2} - Blocks: {3}/{4} - Project Weight: {5}g", ogTitle, curBlockTypeCount, blockTypeCount, curBlockCount, blockCount, currentWeight));

            string fileText = "";

            foreach (KeyValuePair <string, string> block in weightInfo)
            {
                string blockQuantity;
                blockInfo.TryGetValue(block.Key, out blockQuantity);
                fileText += string.Format("Block: {0} | Quantity: {1} | Weight(ea): {2} | Weight(total): {3}g\n\n", block.Key, blockQuantity, block.Value, float.Parse(block.Value.Replace("g", "")) * float.Parse(blockQuantity));
            }

            ChangeCtrlText(this, string.Format("{0} - Writing information to \'{1}\' - Block Types: {2}/{3} - Blocks: {4}/{5} - Project Weight: {6}g", ogTitle, _saveInfoPath, curBlockTypeCount, blockTypeCount, curBlockCount, blockCount, currentWeight));

            using (StreamWriter writer = new StreamWriter(_saveInfoPath)){
                writer.Write(fileText + string.Format("Total Weight: {0}g\nTotal Block Count: {1}", currentWeight, blockCount));
            }

            ChangeCtrlText(this, string.Format("{0} - Finished writing information to \'{1}\' - Block Types: {2}/{3} - Blocks: {4}/{5} - Project Weight: {6}g", ogTitle, _saveInfoPath, curBlockTypeCount, blockTypeCount, curBlockCount, blockCount, currentWeight));
            MessageBox.Show(string.Format("Block Types: {0}/{1}\n\nBlocks: {2}/{3}\n\nProject Weight: {4}g", curBlockTypeCount, blockTypeCount, curBlockCount, blockCount, currentWeight), "Finished calculating weight of project");

            //Cleanup boi
            chromeDriver.Close();
            foreach (Process proc in Process.GetProcessesByName("chromedriver"))
            {
                proc.CloseMainWindow();
            }
            TurnOnInteractables();
        }
예제 #14
0
        public string Spa122(ChromeDriver browser)
        {
            string ATAInfo = "";

            try
            {
                browser.FindElementByName("user").SendKeys(userName);
                browser.FindElementByName("pwd").SendKeys(passWord);
                //login button? no unique ID for it so trying this way, hopefully I can count
                browser.FindElements(By.TagName("input"))[5].Click();
            }
            catch (ElementNotVisibleException e)
            {
                Console.WriteLine($"Ran into error: {e.ToString()} \nAttempting refresh of page.");
                //sometimes page wouldn't load for spa122, will attempt a refresh, but this could go on endlessly soooo
                //nvm just re run old code vs callin whole method.
                browser.Navigate().Refresh();
                browser.FindElementByName("user").SendKeys(userName);
                browser.FindElementByName("pwd").SendKeys(passWord);
                //login button? no unique ID for it so trying this way, hopefully I can count
                browser.FindElements(By.TagName("input"))[5].Click();
                // throw;
            }
            catch (Exception e)
            {
                return(ATAInfo = $"Some error occured logging into ATA, ref: {e.ToString()}");
            }

            try
            {
                //Go to network setup page.
                browser.FindElementById("trt_Network_Service.asp").Click();
                var networkSettings = browser.FindElementById("d_4");
                networkSettings.FindElement(By.TagName("a")).Click();



                //Show DHCP reservations.
                browser.FindElementById("t3").Click();
                //id's could be numbered like an array? need to find an spa122 with mulitples to test that, too bad they're becoming rare...or is it that bad? lolol

                var DHCP_Name = browser.FindElementByName("dhcp_select_name_0");
                var DHCP_IP   = browser.FindElementByName("dhcp_select_ip_0");
                var DHCP_MAC  = browser.FindElementByName("dhcp_select_mac_0");
                ATAInfo += $"DCHP item: \nName:{DHCP_Name.Text}\nLAN IP: {DHCP_IP.Text}\nMAC: {DHCP_MAC.Text}";
            }
            catch (NotFoundException NotHere)
            {
                Console.WriteLine($"Nothing found in DHCP Table {NotHere.ToString()}");
                ATAInfo += "Nothing found in DCHP table\n";
                //throw;
            }
            catch (Exception e)
            {
                return(ATAInfo = $"Couldn't get into ATA {e.ToString()}");
            }

            //Considering there's only one ethernet port on the SPA122, will assume there's one item in DHCP, not always 100%
            //accurate as not every customer lets SPA122 run DHCP, but should be enough to go off of as far as equipment functionality
            //ATAInfo += $"Number of items found in DHCP: {DHCP_IP.Count.ToString()}";
            //Console.WriteLine($"Number of items found in DHCP: {DHCP_IP.Count.ToString()}");
            //for (int dhcp_list = 0; dhcp_list >= DHCP_IP.Count; dhcp_list++)
            //{
            //    ATAInfo += $"DHCP client name: {DHCP_Name[dhcp_list].Text} IP: {DHCP_IP[dhcp_list].Text} MAC: {DHCP_MAC[dhcp_list].Text}";
            //    Console.WriteLine($"DHCP client name: {DHCP_Name[dhcp_list].Text} IP: {DHCP_IP[dhcp_list].Text} MAC: {DHCP_MAC[dhcp_list].Text}");
            //}


            try
            {
                //Check phones
                browser.FindElementById("trt_voice.asp").Click();
                //this page is a mess, hope we really REALLY can count...you really don't wanna see this DOM man. but if you do uncomment this next line, ye be warned
                //Console.WriteLine(browser.PageSource.ToString());

                //Data I want is stored in iframe will have to switch in and out of it.
                browser.SwitchTo().Frame(browser.FindElementById("iframe"));

                //Should be leading DIV containing ALL the info related to voice/uptime.

                var infoDiv   = browser.FindElementById("Information");
                var infoTable = infoDiv.FindElements(By.TagName("tr"))[8];
                infoTable = infoTable.FindElements(By.TagName("td"))[3];
                ATAInfo  += $"ATA up time: {infoTable.FindElement(By.TagName("font")).Text}";
                //Line 1:
                infoTable = infoDiv.FindElements(By.TagName("tr"))[16];
                ATAInfo  += $"Line 1 is {infoTable.FindElements(By.TagName("font"))[0].Text} hook and {infoTable.FindElements(By.TagName("font"))[1].Text} to SIP Server";

                //line 2
                infoTable = infoDiv.FindElements(By.TagName("tr"))[43]; //yeah that many rows in this table
                ATAInfo  += $"Line 2 is {infoTable.FindElements(By.TagName("font"))[0].Text} hook and {infoTable.FindElements(By.TagName("font"))[1].Text} to SIP Server";
            }
            catch (Exception NoIframe)
            {
                ATAInfo += $"Couldn't get voice info, no Iframe found or trouble switching to Iframe, ref: {NoIframe.ToString()}";
                Console.WriteLine($"Couldn't get voice info, no Iframe found or trouble switching to Iframe, ref: {NoIframe.ToString()}");
                throw;
            }

            Console.WriteLine("Going to reboot ATA...");
            //Getting out of iframe, back into orginal DOM
            browser.SwitchTo().DefaultContent();
            //move to reboot ATA
            browser.FindElementById("trt_Management.asp").Click();
            var adminPage = browser.FindElementById("d_20");

            //should be reboot button.
            adminPage.FindElement(By.TagName("a")).Click();
            browser.FindElementById("t4").Click();
            //handle JS alert
            try
            {
                BrowserHelper.HandleAlerts(browser);
            }
            catch (NoAlertPresentException BadAlert)
            {
                Console.WriteLine($"No alert found when attempting reboot, are lines in use? ref: {BadAlert.ToString()}");
                ATAInfo += "No alert found when attempting reboot, are lines in use?";
                // throw;
            }

            return(ATAInfo);
        }
예제 #15
0
        static void parserTest(string cad_num, string driverPath)
        {
            int cnt = 0;

            //string path = @"C:\Users\vtsvetkov\source\repos\pkk_5_parser";
            IWebDriver    driver = new ChromeDriver(driverPath);
            WebDriverWait wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

            driver.Url = @"https://pkk5.rosreestr.ru/#x=1770771.834433252&y=10055441.599232893&z=3&app=search&opened=1";

            Thread.Sleep(1000);

            IWebElement fr = driver.FindElement(By.CssSelector(@"#app-search-form > div > div > div > div > button"));

            Thread.Sleep(1000);
            fr.Click();
            fr = driver.FindElement(By.CssSelector(@"#tag_5"));
            fr.Click();

            try
            {
                int counter = 0;
                int cntr    = 0;

                fr = driver.FindElement(By.CssSelector(@"#search-text"));
                fr.Clear();
                fr.SendKeys(cad_num);

                Thread.Sleep(1000);

                driver.FindElement(By.CssSelector(@"#app-search-submit")).Click();

                wait.Until(ExpectedConditions.ElementExists(By.CssSelector(@"#feature-oks-info > div")));

                while (counter < 20)
                {
                    Thread.Sleep(500);
                    var pane            = driver.FindElements(By.CssSelector(@"#feature-oks-info > div"));
                    var val             = Regex.Replace(pane[0].Text, @"(\r\n)", "#", RegexOptions.Compiled);
                    var condition       = Regex.Match(val, @"Тип:#([^#]+)#", RegexOptions.Compiled).Groups[1].Value;
                    var cad_numFromPane = Regex.Match(val, @"Кад. номер:#([^#]+)#", RegexOptions.Compiled).Groups[1].Value;
                    var equal           = cad_num.Equals(cad_numFromPane);

                    while (!equal)
                    {
                        Thread.Sleep(500);
                        pane            = driver.FindElements(By.CssSelector(@"#feature-oks-info > div"));
                        cad_numFromPane = Regex.Match(val, @"Кад. номер:#([^#]+)#", RegexOptions.Compiled).Groups[1].Value;
                        cntr++;
                        if (cntr > 50)
                        {
                            break;
                        }
                        Console.WriteLine("тупняк " + cntr);
                    }
                    cntr = 0;


                    if (!condition.Equals("-") && equal)
                    {
                        OKS oks = new OKS(val, cad_num);

                        break;
                    }
                    else if (counter == 19)
                    {
                        OKS oks = new OKS(val, cad_num);

                        counter++;
                    }
                    else
                    {
                        counter++;
                    }
                }

                Thread.Sleep(500);
                cnt++;
                //Console.WriteLine(cnt + ") For CAD_NUM " + cad_num + "    counter = " + counter);
            }
            catch (Exception e)
            {
                var name = e.GetType().Name;
                if (name.Equals("ArgumentOutOfRangeException") ||
                    name.Equals("WebDriverTimeoutException"))
                {
                    OKS oks = new OKS(cad_num, e.GetType().Name, -999);
                }
                else
                {
                    OKS oks = new OKS(cad_num, e.GetType().Name, -999);
                }
                //OKS oks = new OKS(cad_num, e.GetType().Name, "", "", "", "", "", "", "", "");
                //elem[i].oks = oks;
            }

            driver.Close();
            //return elem;
        }
예제 #16
0
        public GiftHulkModel(string username, string password, BackgroundWorker bw, bool openHulk, int cards)
        {
            int chips = 0;

            ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);

            service.HideCommandPromptWindow = true;

            ChromeOptions options = new ChromeOptions();

            options.AddArgument("start-maximized");
            options.AddArgument("user-data-dir=" + App.Folder + "profileGH");

            IWebDriver driver = new ChromeDriver(service, options);

            driver.Navigate().GoToUrl("http://www.gifthulk.com/");

            try
            {
                driver.FindElement(By.ClassName("signup-link")).Click();

                driver.FindElement(By.Name("log")).SendKeys(username);
                driver.FindElement(By.Name("pwd")).SendKeys(password);

                /*
                 * IList<IWebElement> iframes = driver.FindElements(By.TagName("iframe"));
                 * MessageBox.Show(iframes.Count.ToString());
                 * foreach(IWebElement iframe in iframes)
                 * {
                 *  MessageBox.Show(iframe.GetAttribute("title"));
                 * }
                 */

                Helpers.switchFrameByNumber(driver, 3);
                //driver.FindElement(By.ClassName("recaptcha-checkbox")).Click();

                /*
                 * if (driver.FindElement(By.Id("recaptcha-anchor")).Displayed)
                 * {
                 *  MessageBox.Show("Hey");
                 * }
                 */
                int classCount = 0;
                IList <IWebElement> ClassNames = driver.FindElements(By.TagName("div"));
                foreach (IWebElement ClassName in ClassNames)
                {
                    if (classCount == 4)
                    {
                        try
                        {
                            ClassName.Click();
                        }
                        catch { }
                    }
                    classCount++;
                }
                driver.SwitchTo().DefaultContent();
                while (driver.FindElement(By.Name("pwd")).Displayed)
                {
                }
                driver.FindElement(By.Name("pwd")).SendKeys(Keys.Enter);
            }
            catch { }
            finally { }
            Helpers.wait(5000);

            Helpers.ByClass(driver, "close-popup");

            if (!openHulk)
            {
                while (!bw.CancellationPending)
                {
                    int.TryParse(driver.FindElement(By.Id("daily_chips")).Text, out chips);

                    if (chips > 0)
                    {
                        driver.Navigate().GoToUrl("http://www.gifthulk.com/guess-the-card/");
                        GuessCard(driver, cards);
                    }

                    try
                    {
                        driver.FindElement(By.Id("watch-video")).Click();
                        sideVideos(driver);
                    }
                    catch { }

                    Helpers.wait(5000);
                    videosWatch(driver);
                }
            }
        }
예제 #17
0
        static void Main(string[] args)
        {
            // Internet Explorer
            //IWebDriver driver = new InternetExplorerDriver(@"C:\libraries");


            /*
             * Chrome trial : Does not work
             */
            //System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", "C:\\Libraries\\chromedriver.exe");
            //ChromeOptions options = new ChromeOptions();
            //options.BinaryLocation = "C:\\Libraries\\chromedriver.exe";
            //options.AddArgument("--test-type");
            //IWebDriver driver = new ChromeDriver(@"C:\Libraries", options);



            /*
             * Two types of wait conditions were used, the one with try/catch is the one generated by the Selenium IDE and the "driver.Manage()..." [line 65], version is manual entry.
             * In order to be able to click the image within Google's Image search, the Image link had to clicked twice [see lines 67 and 93] each with its own time delay, see previous paragraph.
             * It was once this redundant procedure was conducted that the first image result can be clicked on.
             */


            // Firefox default driver
            IWebDriver driver = new ChromeDriver();

            driver.Url = "http://www.google.com";

            var searchField = driver.FindElement(By.Id("lst-ib"));



            searchField.SendKeys("pluralsight");

            // To retrieve a list of results, otherwise google ajax will go into auto-complete
            // mode and render all other page elements null.
            driver.FindElement(By.Id("_fZl")).Click();

            // waitForVisible | css=a.q.qs utilising wait logic from Selenium IDE code export
            //for (int second = 0; ; second++)
            //{
            //    if (second >= 60)
            //    {
            //        Assert.Fail("timeout");
            //    }
            //    try
            //    {
            //        if (driver.FindElement(By.CssSelector("a.q.qs")).Displayed) break;
            //    }
            //    catch (Exception)
            //    { }
            //    Thread.Sleep(1000);
            //}



            // var imagesLink = driver.FindElement(By.CssSelector("div[class='q qs']"));

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            //driver.FindElement(By.CssSelector("a.q.qs")).Click();
            driver.FindElements(By.ClassName("qs"))[0].Click();


            //var someImage = driver.FindElement(By.ClassName("rg_i"));
            //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            //var firstImageLink = someImage.FindElements(By.TagName("a"))[0];
            //firstImageLink.Click();

            //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

            //driver.FindElement(By.Name("rbc9XlfmBObC6M:")).Click();


            //for (int second = 0; ; second++)
            //{
            //    if (second >= 60) Assert.Fail("timeout");
            //    try
            //    {
            //        if (driver.FindElement(By.CssSelector("a.q.qs")).Displayed) break;
            //    }
            //    catch (Exception)
            //    { }
            //    Thread.Sleep(1000);
            //}
            //// second session to find the same image
            //// click | css=a.q.qs |
            //driver.FindElement(By.CssSelector("a.q.qs")).Click();


            // click | name=rbc9XlfmBObC6M: |
            driver.FindElement(By.Name("rbc9XlfmBObC6M:")).Click();
        }
예제 #18
0
        public void ChromeMethod()
        {
            string     ActualResult;
            string     ExpectedResult = "Wikipedia";
            IWebDriver driver         = new ChromeDriver();

            driver.Navigate().GoToUrl("https://www.wikipedia.org");
            driver.Manage().Window.Maximize();

            List <string> CentralLanguages             = new List <string>();
            ReadOnlyCollection <IWebElement> languages = driver.FindElements(By.ClassName("central-featured-lang"));

            foreach (IWebElement language in languages)
            {
                string lang = language.Text;
                lang = lang.Substring(0, lang.LastIndexOf("\r"));
                CentralLanguages.Add(lang);
            }
            string stop = "";

            Thread.Sleep(2000);
            SelectElement selectLanguage = new SelectElement(driver.FindElement(By.Id("searchLanguage")));

            selectLanguage.SelectByText("Deutsch");
            selectLanguage.SelectByValue("be");
            selectLanguage.SelectByIndex(0);

            #region
            List <String> textofanchors = new List <string>();
            ReadOnlyCollection <IWebElement> anchorLists = driver.FindElements(By.TagName("a"));
            foreach (IWebElement anchor in anchorLists)
            {
                if (anchor.Text.Length > 0)
                {
                    if (anchor.Text.Contains("English"))
                    {
                        textofanchors.Add(anchor.Text);
                        anchor.Click();
                    }
                }
            }

            //driver.FindElement(By.Id("searchInput")).SendKeys("Selenium");
            //driver.FindElement(By.ClassName("pure-button")).Click();

            /*
             * ActualResult = driver.Title;
             * if (ActualResult.Contains(ExpectedResult))
             * {
             *  Console.WriteLine("test case Passed !!!");
             *  Assert.IsTrue(true, "test case Passed !!!");
             * }
             * else
             * {
             *  Console.WriteLine("test case Failed !!!");
             * }
             */

            #endregion
            //driver.Close();
            driver.Quit();
        }
예제 #19
0
        private static void Takipci()
        {
            IWebDriver driver = new ChromeDriver();

            Console.WriteLine("Kullanıcı adını girin :");
            string kullanici = Console.ReadLine();

            driver.Navigate().GoToUrl("https://www.instagram.com/" + kullanici + "/followers/");

            System.Threading.Thread.Sleep(3000);

            driver.FindElement(By.Name("username")).SendKeys("*****@*****.**");
            System.Threading.Thread.Sleep(2000);


            System.Threading.Thread.Sleep(1000);

            driver.FindElement(By.Name("password")).SendKeys("886179");
            System.Threading.Thread.Sleep(1000);
            driver.FindElement(By.Name("password")).Submit();

            System.Threading.Thread.Sleep(1000);

            System.Threading.Thread.Sleep(4000);

            IWebElement page = driver.FindElement(By.XPath("//*[@id=\"react-root\"]/section/main/div/header/section/ul/li/a"));

            System.Threading.Thread.Sleep(1000);
            page.Click();
            System.Threading.Thread.Sleep(2000);


            System.Threading.Thread.Sleep(2000);



            var donenSayi = TakipciSayi(driver);

            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;


            double count = 0;

            while (donenSayi != count)
            {
                js.ExecuteScript("var followers = document.querySelector(\".isgrP\"); " +
                                 "followers.scrollBy(0,600);");
                //count = driver.FindElements(By.XPath("//a[@class='FPmhX notranslate _0imsa ']")).Count;
                count = driver.FindElements(By.XPath("/html/body/div/div/div/ul/div/li")).Count;
                System.Threading.Thread.Sleep(1000);
            }


            System.Threading.Thread.Sleep(2000);

            System.Threading.Thread.Sleep(2000);


            //IReadOnlyCollection<IWebElement> searchResult =
            //    driver.FindElements(By.XPath("//a[@class='FPmhX notranslate _0imsa ']"));


            IReadOnlyCollection <IWebElement> searchResult =
                driver.FindElements(By.XPath("//a[@class='FPmhX notranslate  _0imsa ']"));


            foreach (var search in searchResult)
            {
                var t = search.Text;
                Console.WriteLine(t);
                VeriYazTakipciler(t, "Takipçi", kullanici);
            }


            //int count = driver.FindElements(By.XPath("//a[@class='FPmhX notranslate _0imsa ']")).Count;
            //for (int i = 0; i < count; i++)
            //{
            //    Console.WriteLine(driver.FindElements(By.XPath("//a[@class='FPmhX notranslate _0imsa ']"))[i].Text);
            //}
        }
예제 #20
0
        public List <RmlPlayer> BuildRmlPlayers()
        {
            var playerTypes = new List <string>
            {
                "CB",
                "DL"
            };

            var rmlPlayers = new List <RmlPlayer>();

            foreach (var playerType in playerTypes)
            {
                _driver.Navigate().GoToUrl($"http://games.espn.com/ffl/freeagency?leagueId=127291&teamId=8&seasonId={_year}");
                var opLink = _driver.FindElement(By.XPath($"//ul[@class='filterToolsOptionSet']/li/a[contains(.,'{playerType}')]"));
                opLink.Click();

                System.Threading.Thread.Sleep(2000);
                var nextLink = _driver.FindElements(By.XPath("//div[@class='paginationNav']/a[contains(., 'NEXT')]"));

                while (nextLink.Count == 1)
                {
                    nextLink = _driver.FindElements(By.XPath("//div[@class='paginationNav']/a[contains(., 'NEXT')]"));
                    var rmlPlayerRows = _driver.FindElements(By.XPath("//tr[contains(@class, 'pncPlayerRow')]"));

                    foreach (var rmlPlayerRow in rmlPlayerRows)
                    {
                        var rmlPlayer = new RmlPlayer();
                        //TODO: Need to check if the first Position is the one we are looking for (i.e. S, CB => CB)
                        //Chandler Jones, Ari LB, DE, EDR
                        try
                        {
                            rmlPlayer.Team         = rmlPlayerRow.FindElement(By.XPath("./td[@class='playertablePlayerName']")).Text.Split(new string[] { ", " }, StringSplitOptions.None)[1].Split(' ')[0];
                            rmlPlayer.Name         = rmlPlayerRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).Text;
                            rmlPlayer.PreviousRank = int.TryParse(rmlPlayerRow.FindElement(By.XPath("./td[@class='playertableData'][1]")).Text, out _) ?
                                                     int.Parse(rmlPlayerRow.FindElement(By.XPath("./td[@class='playertableData'][1]")).Text) : -1;
                            rmlPlayer.PreviousPoints = decimal.TryParse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][1]")).Text, out _) ?
                                                       decimal.Parse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][1]")).Text) : -10;
                            rmlPlayer.PreviousAverage = decimal.TryParse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][2]")).Text, out _) ?
                                                        decimal.Parse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][2]")).Text) : -10;
                            rmlPlayer.Positions = ParsePositionFromElement(rmlPlayerRow.FindElement(By.XPath("./td[@class='playertablePlayerName']")).Text, rmlPlayer.Name.Length);
                        }
                        catch
                        {
                            System.Threading.Thread.Sleep(30000);
                            rmlPlayer.Team         = rmlPlayerRow.FindElement(By.XPath("./td[@class='playertablePlayerName']")).Text.Split(new string[] { ", " }, StringSplitOptions.None)[1].Split(' ')[0];
                            rmlPlayer.Name         = rmlPlayerRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).Text;
                            rmlPlayer.PreviousRank = int.TryParse(rmlPlayerRow.FindElement(By.XPath("./td[@class='playertableData'][1]")).Text, out _) ?
                                                     int.Parse(rmlPlayerRow.FindElement(By.XPath("./td[@class='playertableData'][1]")).Text) : -1;
                            rmlPlayer.PreviousPoints = decimal.TryParse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][1]")).Text, out _) ?
                                                       decimal.Parse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][1]")).Text) : -10;
                            rmlPlayer.PreviousAverage = decimal.TryParse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][2]")).Text, out _) ?
                                                        decimal.Parse(rmlPlayerRow.FindElement(By.XPath("./td[contains(@class,'playertableStat')][2]")).Text) : -10;
                            rmlPlayer.Positions = ParsePositionFromElement(rmlPlayerRow.FindElement(By.XPath("./td[@class='playertablePlayerName']")).Text, rmlPlayer.Name.Length);
                        }

                        rmlPlayers.Add(rmlPlayer);
                    }

                    if (nextLink.Count == 1)
                    {
                        nextLink[0].Click();
                        System.Threading.Thread.Sleep(5000);
                    }
                }
            }

            return(rmlPlayers);
        }
예제 #21
0
        public void RegisterWithValidData()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Manage().Window.Maximize();
            driver.Url = "http://www.demoqa.com/";

            IWebElement regButton = driver.FindElement(By.XPath("//*[@id=\"menu-item-374\"]"));

            regButton.Click();

            IWebElement firstName = driver.FindElement(By.Id("name_3_firstname"));

            Type(firstName, "Tanya");

            IWebElement lastName = driver.FindElement(By.Id("name_3_lastname"));

            Type(lastName, "Petrova");

            var martialStatus = driver.FindElement(By.XPath("//*[@id=\"pie_register\"]/li[2]/div/div/input[1]"));

            martialStatus.Click();

            List <IWebElement> hobbies = driver.FindElements(By.Name("checkbox_5[]")).ToList();

            hobbies[0].Click();
            hobbies[1].Click();

            SelectOption(driver, "dropdown_7", "Bulgaria");
            SelectOption(driver, "mm_date_8", "3");
            SelectOption(driver, "dd_date_8", "3");
            SelectOption(driver, "yy_date_8", "1978");
            IWebElement phonenumber = driver.FindElement(By.Id("phone_9"));

            Type(phonenumber, "3597878787878");
            IWebElement userName = driver.FindElement(By.Id("username"));

            Type(userName, "tanyta");
            IWebElement email = driver.FindElement(By.Id("email_1"));

            Type(email, "*****@*****.**");

            //IWebElement uploadPicButton = driver.FindElement(By.Id("profile_pic_10"));
            // uploadPicButton.Click();
            //driver.SwitchTo().ActiveElement().SendKeys(@"C:\Users\Pc\Downloads\eee.jpg");
            IWebElement description = driver.FindElement(By.Id("description"));

            Type(description, "Family Wars: Question: Popular movie with Schwarzenegger? Answer correct:ROKI");
            IWebElement password = driver.FindElement(By.Id("password_2"));

            Type(password, "123456789");
            IWebElement confirmPassword = driver.FindElement(By.Id("confirm_password_password_2"));

            Type(confirmPassword, "123456789");
            IWebElement submitButton = driver.FindElement(By.Name("pie_submit"));

            submitButton.Click();
            IWebElement registrationMessage = driver.FindElement(By.ClassName("piereg_message"));

            Assert.IsTrue(regButton.Displayed);
            Assert.AreEqual("Thank you for your registration", registrationMessage.Text);



            driver.Quit();
        }
예제 #22
0
        public void TheBingSearchTest()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl("https://asknypadmindev.azurewebsites.net/botmain");
            driver.Manage().Window.Maximize();
            IWebElement imageclick = driver.FindElement(By.XPath("//img[@src='https://asknypadmin.azurewebsites.net/BotFolder/NYPChatBotRight.png']"));

            imageclick.Click();
            IWebElement frame = driver.FindElement(By.XPath(".//iframe[@id='nypBot']"));

            driver.SwitchTo().Frame(frame);
            driver.FindElement(By.XPath("/html/body/div[1]/div/div/div[3]/div/input")).Click();



            string questions;
            string columnheader;
            string newcolumnheaders;
            string answercells;
            string responsecells;
            int    count    = 0;
            int    yescount = 0;

            excel.Application x1app = new excel.Application();
            x1app.SheetsInNewWorkbook = 1;
            x1app.Visible             = true;
            excel.Workbook x1workbook  = x1app.Workbooks.Open(@"C:\Users\L33539\Desktop\JUNJIE FYP PROJECT\Overall_QnA4");
            excel.Workbook NewWorkBook = x1app.Workbooks.Add();
            for (int x = 4; x <= 7; x++) //original x=4 x<=23
            {
                excel._Worksheet x1worksheet = x1workbook.Sheets[x];
                x1worksheet.Copy(Type.Missing, After: NewWorkBook.Sheets[x - 3]);
            }
            Thread.Sleep(2000);


            for (int w = 2; w <= 5; w++) //original w=2 w<=21
            {
                excel._Worksheet NewWorkSheet = NewWorkBook.Sheets[w];
                excel.Range      NewWorkRange = NewWorkSheet.UsedRange;
                int colCount2 = NewWorkRange.Columns.Count;
                int rowCount2 = NewWorkRange.Rows.Count;
                NewWorkSheet.Cells[colCount2 + 1][1] = "Response";
                NewWorkSheet.Cells[colCount2 + 2][1] = "Timing of response retrieval";
                NewWorkSheet.Cells[colCount2 + 3][1] = "Does the answer and response match?";
                Console.WriteLine("Rows Count: " + (rowCount2 - 1));

                var numOfRes    = 1;
                var newNumOfRes = 0;
                var testString  = "";
                var testString2 = "";

                for (int i = 2; i <= rowCount2; i++)
                {
                    questions = NewWorkRange.Cells[1][i].value2;
                    driver.FindElement(By.XPath("//html/body/div[1]/div/div/div[3]/div/input")).SendKeys(questions); //"Send questions"
                    driver.FindElement(By.XPath("//html/body/div[1]/div/div/div[3]/button[1]")).Click();             //click button to send the question
                    Thread.Sleep(1000);

                    var textboxmsg = driver.FindElements(By.ClassName("format-markdown"));
                    var wrongqnmsg = driver.FindElements(By.XPath("//div[@class='wc-list']"));
                    count += 1;

                    newNumOfRes = textboxmsg.Count() + wrongqnmsg.Count();
                    if (newNumOfRes >= 1)
                    {
                        try
                        {
                            testString = textboxmsg.Last().GetAttribute("outerHTML");
                            Console.WriteLine("MESSAGES :" + testString);
                            testString2 = wrongqnmsg.Last().GetAttribute("outerHTML");
                        }
                        catch { }
                    }
                    while (newNumOfRes == numOfRes)
                    {
                        // Pooling
                        Thread.Sleep(1000);
                        textboxmsg  = driver.FindElements(By.ClassName("format-markdown"));
                        wrongqnmsg  = driver.FindElements(By.XPath("//div[@class='wc-list']"));
                        newNumOfRes = textboxmsg.Count() + wrongqnmsg.Count();
                        try
                        {
                            testString  = textboxmsg.Last().GetAttribute("outerHTML");
                            testString2 = wrongqnmsg.Last().GetAttribute("outerHTML");
                        }
                        catch
                        { }
                    }

                    numOfRes = newNumOfRes;
                    // foreach (var textmsg in textboxmsg)
                    // {
                    for (int c = 1; c <= colCount2 + 2; c++)
                    {
                        columnheader     = NewWorkRange.Cells[1, c].value2;
                        newcolumnheaders = NewWorkSheet.Cells[1, c].value2;
                        answercells      = NewWorkSheet.Cells[i, 2].Text;
                        responsecells    = NewWorkSheet.Cells[i, 3].Text;

                        //retrieve response with all tags then remove all the tags below
                        //try
                        //{
                        var outerhtml = testString; //figure this out later (system no element exception)
                        //}
                        //catch
                        //{

                        //}

                        outerhtml = outerhtml.Replace("<br />", Environment.NewLine);
                        outerhtml = Regex.Replace(outerhtml, @"<(?!a|/a|ol|ul[\x20/>])[^<>]+>", string.Empty);
                        outerhtml = outerhtml.TrimEnd('\r', '\n');  //remove carriage return
                                                                    //all to replace some to match
                        outerhtml = outerhtml.Replace("“", "\"");
                        outerhtml = outerhtml.Replace("”", "\"");
                        outerhtml = outerhtml.Replace("<ul>", "-");
                        outerhtml = outerhtml.Replace("‘", "'");
                        outerhtml = outerhtml.Replace("’", "'");

                        var outerhtml2 = wrongqnmsg.Last().GetAttribute("outerHTML");
                        outerhtml2 = outerhtml2.Replace("<br />", Environment.NewLine);
                        outerhtml2 = Regex.Replace(outerhtml2, @"<(?!a|/a|ol|ul[\x20/>])[^<>]+>", string.Empty);
                        outerhtml2 = outerhtml2.TrimEnd('\r', '\n');  //remove carriage return
                                                                      //all to replace some to match
                        outerhtml2 = outerhtml2.Replace("“", "\"");
                        outerhtml2 = outerhtml2.Replace("”", "\"");
                        outerhtml2 = outerhtml2.Replace("<ul>", "-");
                        outerhtml2 = outerhtml2.Replace("‘", "'");
                        outerhtml2 = outerhtml2.Replace("’", "'");


                        //to replace ol with numerics
                        int           result = 0;
                        StringBuilder sb     = new StringBuilder(outerhtml);
                        result = outerhtml.IndexOf("<ol");
                        while (result > -1)
                        {
                            if (result == outerhtml.IndexOf("<ol>"))
                            {
                                sb.Remove(result, 4);
                                sb.Insert(result, "1)");
                            }
                            else
                            {
                                char number = outerhtml[result + 11];
                                sb.Remove(result, 14);
                                sb.Insert(result, number + ")");
                            }
                            outerhtml = sb.ToString();
                            result    = outerhtml.IndexOf("<ol");
                        }

                        //below is to remove linebreaks and whitespace for both answer and response cells to do matching
                        var compareresponsecells = Regex.Replace(outerhtml, @"\r\n?|\n", "");   //to remove line breaks for comparison
                        compareresponsecells = Regex.Replace(compareresponsecells, @"\s+", ""); //to remove whitespace for comparison
                        var compareanswercells = Regex.Replace(answercells, @"\r\n?|\n", "");
                        compareanswercells = Regex.Replace(compareanswercells, @"\s+", "");

                        //Console.WriteLine(newcolumnheaders);
                        if (columnheader == "Question")
                        {
                        }
                        else if (columnheader == "Answer")
                        {
                        }
                        else if (columnheader == "Answers")
                        {
                        }
                        else if (newcolumnheaders == "Response")
                        {
                            //Console.WriteLine("YES " + count);
                            try
                            {
                                NewWorkSheet.Cells[i, c] = outerhtml;
                                Console.WriteLine("SICK FEELING :" + outerhtml);
                                var wcmessagecontented = driver.FindElements(By.XPath("//div[@class='wc-message-content']"));
                                var lastwcmsgcontent   = wcmessagecontented.Last();
                                var child = lastwcmsgcontent.FindElement(By.XPath("./div/div")); // ./ means go down from this element
                                //Console.WriteLine("LAST CHILD :" + child.GetAttribute("outerHTML"));
                                if (child.GetAttribute("class").Contains("wc-list"))
                                {
                                    NewWorkSheet.Cells[i, c] = outerhtml2;
                                    //Console.WriteLine("Panini");
                                }
                                //NewWorkSheet.Cells[i, c] = outerhtml2;
                            }
                            catch
                            {
                            }
                            //outerhtml.Contains((char)13);
                            //Console.WriteLine(outerhtml.Contains((char)13));
                            //Console.WriteLine("WELP:" + outerhtml);
                        }
                        else if (newcolumnheaders == "Timing of response retrieval")
                        {
                            try
                            {
                                NewWorkSheet.Cells[i, c] = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
                            }
                            catch
                            {
                            }
                        }
                        else if (newcolumnheaders == "Does the answer and response match?")
                        {
                            if (compareanswercells.Equals(compareresponsecells))
                            {
                                try
                                {
                                    NewWorkSheet.Cells[i, c] = "Yes";
                                }
                                catch
                                {
                                }
                            }
                            else
                            {
                                try
                                {
                                    NewWorkSheet.Cells[i, c] = "No";
                                }
                                catch
                                {
                                }
                            }
                        }
                        else if (columnheader == null)
                        {
                        }
                        else
                        {
                            try
                            {
                                NewWorkSheet.Columns[c].Delete();
                                c--;
                            }
                            catch
                            {
                            }
                        }
                    }
                    // }
                    if (NewWorkSheet.Cells[i, 5].Text == "Yes")
                    {
                        yescount += 1;
                        //Console.WriteLine("For yes:" + NewWorkSheet.Cells[1][i].Text);
                        //Console.WriteLine("Yes: " + yescount);
                    }
                    else
                    {
                    }
                    //Console.WriteLine("TOTALMATCHCOUNT:" + count);

                    //x1workbook.SaveAs(path, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                }
                excel._Worksheet NewWorkSheet1 = NewWorkBook.Sheets[1];
                excel.Range      NewWorkRange1 = NewWorkSheet1.UsedRange;
                //int colCount3 = NewWorkRange.Columns.Count;
                //int rowCount3 = NewWorkRange.Rows.Count;
                NewWorkSheet1.Cells[1][1] = "Total Count of Matches: " + count;
                NewWorkSheet1.Cells[1][2] = "Total Count of Matches Matched: " + yescount;
            }
        }
        /*
         * author : yuha
         * funcName : crawlingFromStockx
         * summary : stockx 크롤링
         * input : searchVo.useKrw
         * return : Dictionary<string, DetailInfo>
         */
        public Dictionary <string, DetailInfo> crawlingFromStockx(SearchVo searchVo)
        {
            /*stockX 정보 수집 시작*/
            _driver = new ChromeDriver(_driverService, _options);

            string url         = searchVo.stockXUrl;
            string after_url   = searchVo.makeStockXUrl(url);
            int    j           = 0;
            bool   sizeDefault = false;

            searchVo.clothesYn = false;
            searchVo.sizeType  = " ";

            // _driver.Navigate().GoToUrl(after_url); // 웹 사이트에 접속합니다.
            _driver.Navigate().GoToUrl(url); // 웹 사이트에 접속합니다.
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            Dictionary <string, string> usKrSizeMap = sizeConstantMap.getUsKrSizeMap();
            float usdkrw = searchVo.usdkrw;

            Thread.Sleep(3000);
            //첫 화면 팝업
            var popElement = _driver.FindElementByXPath("//*[contains(@aria-label,'Close')]");

            popElement.Click();
            Thread.Sleep(5000);

            string prdNm    = searchVo.prdNm;
            string sizeType = " ";

            /***2021-02-11 추가****////
            //사이즈별 최근 판매가
            Dictionary <string, float> latestSalePrcMap = new Dictionary <string, float>();
            //
            Dictionary <string, float> latestSalePrcDiffMap = new Dictionary <string, float>();

            //최근 판매가 리스트 열어주는 버튼
            var latestBtn = (_driver.FindElementsByXPath("//*[contains(@data-testid,'product-size-select')]"))[1];

            latestBtn.Click();
            Thread.Sleep(1000);

            //사이즈별 최근 판매가 리스트
            var latestHead = (_driver.FindElementsByXPath("//*[contains(@class,'select-control')]"))[1];
            var latestList = latestHead.FindElements(By.XPath(".//*[contains(@role,'menuitem')]"));

            // 최근 판매가 각 사이즈
            string sizeText2 = latestList[1].FindElement(By.ClassName("title")).Text.Replace("US ", "");

            //최근 판매가 메인 > 사이즈 타입 > 사이즈 매핑
            if (sizeText2.Contains("W"))
            {
                sizeType          = "W";
                searchVo.sizeType = sizeType;
                usKrSizeMap       = sizeConstantMap.getUsKrSizeWMap();
            }
            else if (sizeText2.Contains("Y"))
            {
                sizeType          = "Y";
                searchVo.sizeType = sizeType;
                usKrSizeMap       = sizeConstantMap.getUsKrSizeYMap();
            }
            else if ("SMLXL".Contains(sizeText2))
            {
                sizeType           = " ";
                searchVo.sizeType  = sizeType;
                usKrSizeMap        = sizeConstantMap.getClothesSizeMap();
                searchVo.clothesYn = true;
            }
            else
            {
                sizeDefault = true;
            }

            for (int i = 1; i < latestList.Count; i++)
            {
                //각 사이즈를 눌러 최근가를 조회
                latestList[i].Click();
                Thread.Sleep(2000);

                latestBtn.Click();
                Thread.Sleep(2000);

                //최근 판매가
                string latestSalePrc = _driver.FindElementByXPath("//*[contains(@data-testid,'product-last-sale-button')]").FindElement(By.ClassName("sale-value")).Text;
                //현재가 (초록색)
                string buyPrc = _driver.FindElementsByXPath("//*[contains(@data-testid,'product-bidbuy-btn')]")[1].FindElement(By.ClassName("stat-value")).Text.Replace("$", "");
                string sizeKey;

                //최근판매가 없으면 추가x
                if (!latestSalePrc.Contains("-"))
                {
                    if (!buyPrc.Contains("-"))
                    {
                        latestSalePrc = latestSalePrc.Replace("$", "");
                        //맵핑 시 사이즈 키 구하기 ( 예 : US4 => 사이즈키 : 4 )
                        sizeKey = latestList[i].FindElement(By.ClassName("title")).Text.Replace("us ", "").Replace("US ", "").Replace(sizeType, "");

                        //최근 판매가 맵에 최근가 추가
                        latestSalePrcMap.Add(sizeKey, float.Parse(latestSalePrc));
                        //최근 판매가 차이 맵에 차이값 추가 ( 최근 판매가 - 현재가 )
                        latestSalePrcDiffMap.Add(sizeKey, float.Parse(latestSalePrc) - float.Parse(buyPrc));
                    }
                }
            }

            _driver.Url = after_url;
            /***2021-02-11 추가 끝****/

            var li = _driver.FindElements(By.ClassName("tile-inner"));
            //사이즈 타입
            string sizeText = li[0].FindElement(By.ClassName("tile-value")).Text.Replace("US ", "");
            //List<string> testList = new List<string>();
            List <int> index = new List <int>();

            Dictionary <string, DetailInfo> InfoMap = new Dictionary <string, DetailInfo>();

            if (sizeText.Contains("W"))
            {
                sizeType          = "W";
                searchVo.sizeType = sizeType;
                usKrSizeMap       = sizeConstantMap.getUsKrSizeWMap();
            }
            else if (sizeText.Contains("Y"))
            {
                sizeType          = "Y";
                searchVo.sizeType = sizeType;
                usKrSizeMap       = sizeConstantMap.getUsKrSizeYMap();
            }
            else if ("SMLXL".Contains(sizeText))
            {
                sizeType           = " ";
                searchVo.sizeType  = sizeType;
                usKrSizeMap        = sizeConstantMap.getClothesSizeMap();
                searchVo.clothesYn = true;
            }
            else
            {
                sizeDefault = true;
            }

            for (int i = 0; i < li.Count; i++)
            {
                //세금 뺀 원 판매가
                string price = li[i].FindElement(By.XPath("div[@class='tile-subvalue']/div")).Text.Replace("$", "");
                float  size;
                if (!price.Equals("Bid"))
                {
                    if (sizeDefault)
                    {
                        //사이즈 4~12 사이인것들만 인덱스 맵 추가
                        size = float.Parse(li[i].FindElement(By.ClassName("tile-value")).Text.Replace("US ", "").Replace(sizeType, ""));
                        if (size >= 4 && size <= 12)
                        {
                            index.Add(i);
                        }
                    }
                    else
                    {
                        index.Add(i);
                    }
                }
            }
            //두번째 메인 인덱스 맵 순회
            foreach (int i in index)
            {
                var    innerList = _driver.FindElements(By.ClassName("tile-inner"));
                string test      = innerList[i].FindElement(By.ClassName("tile-value")).Text;
                string size      = innerList[i].FindElement(By.ClassName("tile-value")).Text.Replace("US ", "").Replace(sizeType, "");
                try
                {
                    innerList[i].Click();
                }
                catch (ElementClickInterceptedException ex)
                {
                    _driver.ExecuteScript("window.scrollTo(0, document.body.scrollHeight);");
                    Thread.Sleep(1000);
                    innerList[i].Click();
                }
                Thread.Sleep(3000);

                //토탈값 (맨마지막)
                var totalPrc = (_driver.FindElementsByXPath("//*[contains(@data-testid,'bid-total')]"))[3].Text.Replace("$", "");
                //원값 (맨 첫)
                var oriPrc           = _driver.FindElement(By.ClassName("amount")).Text;
                var improtDutyPrc    = (_driver.FindElementsByXPath("//*[contains(@data-testid,'bid-total')]"))[0].Text.Replace("$", "");
                var processingFeePrc = (_driver.FindElementsByXPath("//*[contains(@data-testid,'bid-total')]"))[1].Text.Replace("$", "");
                //원 값+PROCESSING FEE+SHIPPING
                var stockXUsPrice = float.Parse(oriPrc) + float.Parse(processingFeePrc) + 9;

                InfoMap.Add(size, new DetailInfo()
                {
                    usSize = size, krSize = usKrSizeMap[size], stockXUsPrice = stockXUsPrice, stockXKrPrice = (float)Math.Round(stockXUsPrice * usdkrw), prdNm = prdNm
                });

                if (latestSalePrcMap.ContainsKey(size))
                {
                    InfoMap[size].stockXLatestUsPrice = InfoMap[size].stockXUsPrice + latestSalePrcDiffMap[size];
                    InfoMap[size].stockXLatestKrPrice = (float)Math.Round((InfoMap[size].stockXLatestUsPrice) * usdkrw);
                }

                var backBtn = _driver.FindElements(By.ClassName("buy-sell-size"));
                if (backBtn.Count > 1)
                {
                    backBtn[1].Click();
                }
                else
                {
                    backBtn[0].Click();
                }

                Thread.Sleep(2000);
            }

            Thread.Sleep(3000);
            _driver.Quit();

            return(InfoMap);
        }
예제 #24
0
        public List <Bet9ja> Scrape()
        {
            ChromeOptions opt = new ChromeOptions();

            //opt.AddArgument("--headless");

            ChromeDriverService service = ChromeDriverService.CreateDefaultService();
            //service.HideCommandPromptWindow = true;

            var Bet9jaData = new List <Bet9ja>();

            using (var driver = new ChromeDriver())
            {
                //navigate to url for today's matches
                driver.Navigate().GoToUrl("https://web.bet9ja.com/Sport/OddsToday.aspx?IDSport=590");


                var curindex = 0;
                var total    = 1;

                var curId  = "";
                var nextId = "n";

                var sb = new Bet9ja();

                while (curindex < total)
                {
                    System.Threading.Thread.Sleep(5000);

                    //gets all leagues for today
                    var webElements = driver.FindElements(By.XPath("//div[contains(@class, 'oddsViewPanel')]/div[contains(@class, 'divOdds')]/div[contains(@class, 'SEs')]/div[contains(@class, 'item')]"));

                    //reset total count to count of all the matches in the page from the initial (1)
                    if (total == 1)
                    {
                        total = webElements.Count;
                    }
                    else //what to do if total is no more at the initial value (1)
                    {
                        if (total != webElements.Count) //what to do if total no longer matches with count of all the matches in the page. Most likely due so some matches have started.
                        {
                            total = webElements.Count; // assign the new count to total

                            if (nextId != "")          // nextId is empty if the previous was the last
                            {
                                for (int i = 0; i < webElements.Count; i++)
                                {
                                    if (webElements[i].FindElement(By.ClassName("ID")).Text == nextId)
                                    {
                                        curindex = i;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    curId = webElements[curindex].FindElement(By.ClassName("ID")).Text;
                    if ((curindex + 1) < total)
                    {
                        nextId = webElements[curindex + 1].FindElement(By.ClassName("ID")).Text;
                    }
                    else
                    {
                        nextId = "";
                    }

                    if (webElements[curindex].GetAttribute("class").Contains("firstItemGroup"))
                    {
                        if (sb.Matches != null)
                        {
                            Bet9jaData.Add(sb);
                        }

                        sb = new Bet9ja()
                        {
                            League = GetLeague(webElements[curindex]), Matches = new List <Bet9jaMatches>()
                        };
                    }



                    //total = webElements.Count;

                    var matchdiv = webElements[curindex].FindElement(By.ClassName("Event"));
                    matchdiv.Click();

                    System.Threading.Thread.Sleep(5000);

                    var SElement = driver.FindElement(By.XPath("//*[@id=\"divDett\"]"));
                    var match    = GetMatch(SElement);

                    sb.Matches.Add(match);

                    IJavaScriptExecutor js = driver as IJavaScriptExecutor;
                    js.ExecuteScript("history.back()");

                    curindex++;
                }

                if (sb.Matches != null)
                {
                    Bet9jaData.Add(sb);
                }

                return(Bet9jaData);
            }
        }
예제 #25
0
        public void InsertarDocumento()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Url = "http://10.19.178.18/matriz_mantenimiento.asp";

            //Acceso
            driver.FindElement(By.Name("nomina")).SendKeys("251");
            driver.FindElement(By.Name("clave")).SendKeys("0000");
            driver.FindElement(By.Name("B3")).Click();

            if (documentType == "ISO")
            {
                driver.FindElement(By.LinkText("ISO-14001")).Click();
            }
            else if (documentType == "OHSAS")
            {
                driver.FindElement(By.LinkText("OHSAS")).Click();
            }

            var linksNew = driver.FindElements(By.LinkText("Nuevo Procedimiento"));

            if (linksNew.Count > 0)
            {
                var linkNew = linksNew[0];
                linkNew.Click();

                driver.FindElement(By.Name("numero")).SendKeys(nameDocument);
                driver.FindElement(By.Name("nombre")).SendKeys(description);
                driver.FindElement(By.Name("cambio")).SendKeys(version);
                driver.FindElement(By.Name("fecha")).SendKeys(fecha);
                driver.FindElement(By.Name("original")).SendKeys("CIT");
                driver.FindElement(By.Name("copias")).SendKeys("0");

                var area          = driver.FindElement(By.Name("area"));
                var selectElement = new SelectElement(area);
                selectElement.SelectByValue(idAreaFrames);


                var buttonSave = driver.FindElement(By.Name("B1"));
                buttonSave.Click();
                Console.WriteLine("Saving the document....");

                //Regresamos a la pantalla inicial
                var linkRegresar = driver.FindElement(By.LinkText("Regresar"));
                linkRegresar.Click();

                //Consultamos con 1000 registros por tabla.
                driver.FindElement(By.Name("fil")).Clear();
                driver.FindElement(By.Name("fil")).SendKeys(numRegistrosXpagina);
                driver.FindElement(By.Name("B1")).Click();

                //Buscamos todos los elementos <table> del documento.
                var tables = driver.FindElements(By.TagName("table"));
                //Obtenemos la tabla en la posición #1
                var table = tables[1];
                //Obtenemos todos los elementos <tr> de la tabla.
                var columns = table.FindElements(By.TagName("tr"));


                int  i             = 0;
                bool banEncontrado = false;
                bool banNext       = true;
                int  numPagina     = 1;

                do
                {
                    //Iteramos cada columna
                    while (i < columns.Count && !banEncontrado)
                    {
                        //Obtenemos todos los elementos <td> de la columna
                        var rows = columns[i].FindElements(By.TagName("td"));
                        int j    = 0;
                        //Iteramos los elementos td
                        while (j < rows.Count && !banEncontrado)
                        {
                            try
                            {
                                var td = rows[j];
                                //Obtenemos todos los elementos <a> del row actual.
                                var a = td.FindElement(By.TagName("a"));
                                //Verificamos si el elemento <a> tiene los atributos de matriz_cambios_muestra (Lo que significa que es el link para realizar el cambio)
                                if (a.GetAttribute("href").Contains("matriz_cambios_muestra") && a.GetAttribute("href").Contains(nameDocument))
                                {
                                    //Simulamos el click para entrar a realizar las modificaciones necesarias.
                                    a.Click();
                                    //Seteamos para salir de los bucles.
                                    banEncontrado = true;
                                    banNext       = false;
                                }
                            }
                            catch (NoSuchElementException)
                            {
                            }
                            j++;
                        }
                        i++;
                    }

                    //Si no fué encontrado el numero de documento en la página, simulamos el click en la paginación siguiente.
                    if (!banEncontrado)
                    {
                        numPagina++;
                        string href = "http://10.19.178.18/matriz_mantenimiento.asp?pag=" + numPagina + "&fil=" + numRegistrosXpagina + "&campo=nombre";

                        var tablePagination = tables[2];
                        //var listaA = tablePagination.FindElements(By.TagName("a")).Where(z => z.GetAttribute("href").Contains(href)).ToList();
                        var tr = tablePagination.FindElement(By.TagName("tr"));

                        var td = tr.FindElement(By.TagName("td"));

                        var listaA = td.FindElements(By.TagName("a")).Where(z => z.GetAttribute("href").Contains(href)).ToList();

                        if (listaA.Count > 0)
                        {
                            var linkNext = listaA[0];
                            linkNext.Click();

                            tables  = driver.FindElements(By.TagName("table"));
                            table   = tables[1];
                            columns = table.FindElements(By.TagName("tr"));
                            i       = 0;
                        }
                    }
                } while (banNext);

                //Establecemos el valor de numero de documento en el campo liga.
                driver.FindElement(By.Name("liga")).SendKeys(nameDocument);

                var buttonSaveChanges = driver.FindElement(By.Name("B1"));
                buttonSaveChanges.Click();

                //Regresamos a la pantalla inicial
                //var linkRegresar1 = driver.FindElement(By.LinkText("Regresar"));
                //linkRegresar1.Click();

                driver.Close();
                Console.WriteLine("Proceso de inserción finalizado correctamente.");
            }
        }
예제 #26
0
        private void TimerEventProcessor(Object myObject,
                                         EventArgs myEventArgs)
        {
            if (working == false)
            {
                chromeDriver.Navigate().Refresh();

                WaitAjaxLoading(By.Id("errorMessage-title"));
                ReadOnlyCollection <IWebElement> msgErrorBox = chromeDriver.FindElements(By.Id("errorMessage-title"));
                if (msgErrorBox.Count > 0)
                {
                    ReadOnlyCollection <IWebElement> buttonClose = chromeDriver.FindElements(By.Id("errorMessage-closeButton"));
                    if (buttonClose.Count > 0)
                    {
                        string tbuttonClose = buttonClose.First().TagName;
                        if (tbuttonClose == "button")
                        {
                            buttonClose.First().Click();
                        }
                        WaitLoading();
                        Login();
                    }
                }

                ReadOnlyCollection <IWebElement> sessionTerminatedErrorBox = chromeDriver.FindElements(By.XPath("//div[text()='Session terminated' and contains(@id, 'innerCt')]"));
                if (sessionTerminatedErrorBox.Count > 0)
                {
                    ReadOnlyCollection <IWebElement> buttonClose = chromeDriver.FindElements(By.XPath("//span[text()='Close' and contains(@id, 'btnInnerEl')]"));
                    if (buttonClose.Count > 0)
                    {
                        IWebElement abuttonClose = buttonClose.First().FindElement(By.XPath("..")).FindElement(By.XPath("..")).FindElement(By.XPath(".."));
                        string      tbuttonClose = abuttonClose.TagName;
                        if (tbuttonClose == "a")
                        {
                            abuttonClose.Click();
                        }
                        WaitLoading();
                        Login();
                    }
                }

                // If logout
                ReadOnlyCollection <IWebElement> loginForm = chromeDriver.FindElements(By.Id("loginForm"));
                if (loginForm.Count > 0)
                {
                    Login();
                }

                // button-1217 -- Close
                popup = false;
                WaitAjaxLoading(By.XPath("//span[text()='Close' and contains(@id, 'btnInnerEl')]"));
                ReadOnlyCollection <IWebElement> buttonClosepp = chromeDriver.FindElements(By.XPath("//span[text()='Close' and contains(@id, 'btnInnerEl')]"));
                if (buttonClosepp.Count > 0)
                {
                    popup = true;
                    IWebElement abuttonClose = buttonClosepp.First().FindElement(By.XPath("..")).FindElement(By.XPath("..")).FindElement(By.XPath(".."));
                    string      tbuttonClose = abuttonClose.TagName;
                    if (tbuttonClose == "a")
                    {
                        abuttonClose.Click();
                    }
                    WaitLoading();
                }
            }
        }
예제 #27
0
        static void Main(string[] args)
        {
            //Declare Objects
            IWebDriver    driver    = new ChromeDriver();
            Random        random    = new Random();
            Names         NameClass = new Names();
            StringBuilder strings   = new StringBuilder();

            //Declare Variables
            int  length = 10;
            char letter;

            Console.WriteLine("Enter the URL");
            string URL = Console.ReadLine();

ResetPage:

            firstimeonly = true;
            driver.Navigate().GoToUrl(URL);
            int namesl    = random.Next(0, 4000);
            int sectionsl = random.Next(1, 4);
            int rolls     = random.Next(1, 60);

            for (int i = 0; i < length; i++)
            {
                double flt   = random.NextDouble();
                int    shift = Convert.ToInt32(Math.Floor(25 * flt));
                letter = Convert.ToChar(shift + 65);
                strings.Append(letter);
            }

NextPage:

            Thread.Sleep(300);

            try
            {
                ReadOnlyCollection <IWebElement> options   = driver.FindElements(By.ClassName("appsMaterialWizToggleRadiogroupOffRadio"));
                ReadOnlyCollection <IWebElement> textinput = driver.FindElements(By.ClassName("quantumWizTextinputPaperinputInput"));
                ReadOnlyCollection <IWebElement> parainput = driver.FindElements(By.ClassName("quantumWizTextinputPapertextareaInput"));

                foreach (var item in options)
                {
                    item.Click();
                }
                foreach (var item in textinput)
                {
                    item.SendKeys(strings.ToString());
                }
                foreach (var item in parainput)
                {
                    item.SendKeys(strings.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            if (firstimeonly == true)
            {
                driver.FindElement(By.XPath("//*[@id='mG61Hd']/div[2]/div/div[3]/div[1]/div/div/span")).Click();
                firstimeonly = false;
                goto NextPage;
            }

            try
            {
                driver.FindElement(By.XPath("//*[@id='mG61Hd']/div[2]/div/div[3]/div[1]/div/div[2]/span/span")).Click();
                goto NextPage;
            }
            catch
            {
                goto ResetPage;
            }
        }
예제 #28
0
        static void Main(string[] args)
        {
            ChromeDriver  drv;
            ChromeOptions chromeCapabilities = new ChromeOptions();

            chromeCapabilities.EnableMobileEmulation("iPhone X");
            ChromeDriverService service = ChromeDriverService.CreateDefaultService();

            drv = new ChromeDriver(chromeCapabilities);

            drv.Navigate().GoToUrl("https://www.instagram.com/accounts/login/?next=https://www.instagram.com/hasancankayahck/");
            Thread.Sleep(3000);

            var x = drv.FindElements(By.XPath("//input[@class='_2hvTZ pexuQ zyHYP']"));

            x[0].SendKeys("username");
            x[1].SendKeys("password");
            string girishtml = drv.PageSource;
            var    giris     = new HtmlDocument();

            giris.LoadHtml(girishtml);
            var b = giris.DocumentNode.SelectNodes("//button[@class='sqdOP  L3NKy   y3zKF     ']");

            drv.FindElement(By.XPath(b[1].XPath)).Click();
            Thread.Sleep(5000);
            drv.FindElement(By.XPath("//button[@class='sqdOP yWX7d    y3zKF     ']")).Click();



            string html = drv.PageSource;
            var    doc  = new HtmlDocument();

            doc.LoadHtml(html);
            var followersayisi = doc.DocumentNode.SelectSingleNode("//a[@class=' _81NM2']/span").Attributes["title"].Value.Replace(".", "");
            int takipcisayi    = Convert.ToInt32(followersayisi);
            var a               = doc.DocumentNode.SelectNodes("//a[@class='-nal3 ']");
            var followsayi      = a[1].FirstChild.InnerText.Replace(".", "");
            int takipedilensayi = Convert.ToInt32(followsayi);

            drv.FindElement(By.XPath("//a[@class=' _81NM2']")).Click();
            Thread.Sleep(3000);
            List <string> takipci = new List <string>();
            Actions       action  = new Actions(drv);


            string html4 = drv.PageSource;
            var    doc4  = new HtmlDocument();

            doc4.LoadHtml(html4);
            Thread.Sleep(3000);

            int i = 0;

            do
            {
                //action.SendKeys(Keys.Space).Build().Perform();     bu ya da alttaki satır sayfayı aşağı indirmek için kullanılabilir.
                ((IJavaScriptExecutor)drv).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 150)");
                Thread.Sleep(1500);
                i++;
            } while (i < 250);
            // i<250 deneme olarak koyuldu. takipcisyaisi/5 şeklinde düzenlenebilir.

            var followers3 = drv.FindElements(By.XPath("//a[@class='FPmhX notranslate  _0imsa ']"));

            foreach (var item in followers3)
            {
                takipci.Add(item.Text);
            }
            Console.ReadLine();
        }
예제 #29
0
        //DCU Login
        private void DCUlogin()
        {
            //Open Chrome window
            ChromeOptions options = new ChromeOptions();

            options.AddArgument("user-data-dir=C:/Users/RJ's Desktop/AppData/Local/Google/Chrome/User Data/Profile 1");
            var cd = new ChromeDriver(options);

            //naviagte to DCU.org and login
            cd.Url = @"https://www.dcu.org/";
            cd.Navigate();
            IWebElement r = cd.FindElementById("userid");

            r.SendKeys(DCU_User);
            r = cd.FindElementById("password");
            r.SendKeys(DCU_Pass);
            r = cd.FindElementById("submitBtn");
            r.Click();

            //MessageBox.Show("derp wait");
            cd.SwitchTo().Frame("appContainer");
            //Get Data for Checking
            new WebDriverWait(cd, TimeSpan.FromSeconds(20));
            new WebDriverWait(cd, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span"))));
            r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span"));
            lblDCUCheckingData.Text = r.GetAttribute("innerHTML");



            //Get Data for Savings
            r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1014']/div[2]/div[2]/div[1]/div[2]/span"));
            lblDCUSavingsData.Text = r.GetAttribute("innerHTML");

            //Get Data for VISA Credit Card
            r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1023']/div/div[2]/div[1]/div[2]/span"));
            lblDCUCreditData.Text = r.GetAttribute("innerHTML");

            //Change to account sheet for dcu
            WriteToExcel dcuExcel = new WriteToExcel();

            currentSheet = 2;
            dcuExcel.ChangeSheet(currentSheet);

            //Store accounts data in DCU_data
            DCU_data accounts = new DCU_data()
            {
                Checking = lblDCUCheckingData.Text,
                Savings  = lblDCUSavingsData.Text,
                Credit   = lblDCUCreditData.Text
            };

            WriteToExcel.writeAccountsToExcelDCU(accounts);


            //navigate to checking table
            r = cd.FindElement(By.XPath(".//*[@id='ext-gen43']/span"));
            r.Click();


            //cd.SwitchTo().Frame("appContainer");
            new WebDriverWait(cd, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='lblAccountGrid']/span/h3"))));



            //obtain data
            IWebElement test = cd.FindElement(By.XPath(".//*[@id='lblAccountGrid']/span/h3"));

            System.Threading.Thread.Sleep(10000);

            //Check for number of rows to obtain data from
            for (int x = 1; x < 1000;)
            {
                // Store detected elements in a data list
                List <IWebElement> elementList = new List <IWebElement>();
                elementList.AddRange(cd.FindElements(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[2]/div")));

                if (elementList.Count > 0)
                {
                    x++;
                    lbltest.Text = x.ToString();
                }
                else
                {
                    break;
                }
            }
            //Convert element count to an integer. Decrease by 1 for accuracy when looping.
            int checkEleCount = Convert.ToInt32(lbltest.Text);

            checkEleCount--;

            //change to checking excel sheet
            currentSheet = 3;
            dcuExcel.ChangeSheet(currentSheet);


            //Add data for each transaction
            for (int x = 1; x <= checkEleCount;)


            {
                Label[] activeLabel = { lblDateRes,
                                        lblDesRes,
                                        lblDeposRes,
                                        lblWithRes,
                                        lblBalRes, };

                // Default strings. Changes after assigned new value.
                string   activeDate     = "No good";
                string   activeDes      = "No good";
                string   activeDepos    = "No good";
                string   activeWith     = "No good";
                string   activeBal      = "No good";
                string[] currentElement = { activeDate, activeDes, activeDepos, activeWith, activeBal };

                //loop through each part of a row for each transaction
                for (int y = 2; y < 7;)

                {
                    try


                    {
                        r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]/div"));
                        activeLabel[y - 2].Text = r.GetAttribute("innerHTML");
                        currentElement[y - 2]   = activeLabel[y - 2].Text;
                    }
                    catch (NoSuchElementException)
                    {
                        r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]"));
                        activeLabel[y - 2].Text = r.GetAttribute("innerHTML");
                        currentElement[y - 2]   = activeLabel[y - 2].Text;
                    }


                    //go to next column in the row
                    y++;
                }

                DCU_data transactions = new DCU_data
                {
                    Date        = currentElement[0],
                    Description = currentElement[1],
                    Deposit     = currentElement[2],
                    Withdrawl   = currentElement[3],
                    Balance     = currentElement[4],
                };

                WriteToExcel.writeTransactionsToExcelDCU(transactions);
                //MessageBox.Show("Details were successfully added to the excel file!", "Success..", MessageBoxButtons.OK, MessageBoxIcon.Information);
                x++;
            }

            cd.Navigate().Back();



            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ///////////////////////////////////////////////////////////////Credit/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //MessageBox.Show("derp wait");
            cd.SwitchTo().Frame("appContainer");



            new WebDriverWait(cd, TimeSpan.FromSeconds(20));
            new WebDriverWait(cd, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span"))));
            r = cd.FindElement(By.XPath(".//*[@id='ext-comp-1014']/div[1]/div[2]/div[1]/div[2]/span"));


            //navigate to credit table
            r = cd.FindElement(By.XPath(".//*[@id='ext-gen55']/span"));
            r.Click();


            //cd.SwitchTo().Frame("appContainer");
            new WebDriverWait(cd, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='lblAccountGrid']/span/h3"))));



            //obtain data
            IWebElement testCredit = cd.FindElement(By.XPath(".//*[@id='lblAccountGrid']/span/h3"));

            System.Threading.Thread.Sleep(10000);

            //Check for number of rows to obtain data from. This will rarely ever exceed 1000 per month.
            for (int x = 1; x < 1000;)
            {
                // Store detected elements in a data list
                List <IWebElement> elementList = new List <IWebElement>();
                elementList.AddRange(cd.FindElements(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[2]/div")));

                if (elementList.Count > 0)
                {
                    x++;
                    lbltest.Text = x.ToString();
                }
                else
                {
                    break;
                }
            }

            //Convert element count to an integer. Decrease by 1 for accuracy when looping
            int checkEleCountCredit = Convert.ToInt32(lbltest.Text);

            checkEleCountCredit--;


            //Change to credit dcu excel sheet
            WriteToExcel dcuExcelCredit = new WriteToExcel();

            currentSheet = 4;
            dcuExcelCredit.ChangeSheet(currentSheet);

            //Add data for each transaction
            for (int x = 1; x <= checkEleCountCredit;)


            {
                Label[] activeLabel = { lblDateRes,
                                        lblDesRes,
                                        lblDeposRes,
                                        lblWithRes,
                                        lblBalRes, };

                // Default strings. Changes after assigned new value
                string   activeDate     = "No good";
                string   activeDes      = "No good";
                string   activeDepos    = "No good";
                string   activeWith     = "No good";
                string   activeBal      = "No good";
                string[] currentElement = { activeDate, activeDes, activeDepos, activeWith, activeBal };

                //loop through each part of a row for each transaction
                for (int y = 2; y < 7;)

                {
                    try


                    {
                        r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]/div"));
                        activeLabel[y - 2].Text = r.GetAttribute("innerHTML");
                        currentElement[y - 2]   = activeLabel[y - 2].Text;
                    }
                    catch (NoSuchElementException)
                    {
                        r = cd.FindElement(By.XPath(".//*[@id='ext-gen34']/table/tbody/tr[" + x + "]/td[" + y + "]"));
                        activeLabel[y - 2].Text = r.GetAttribute("innerHTML");
                        currentElement[y - 2]   = activeLabel[y - 2].Text;
                    }



                    y++;
                }

                DCU_data transactions = new DCU_data
                {
                    Date        = currentElement[0],
                    Description = currentElement[1],
                    Deposit     = currentElement[2],
                    Withdrawl   = currentElement[3],
                    Balance     = currentElement[4],
                };

                WriteToExcel.writeTransactionsToExcelDCU(transactions);

                x++;



                //for (int data = 0; data < 5;)
                //{
                //    if (activeData[data] == "&nbsp;")
                //    {
                //        activeData[data] = "";
                //    }

                //    data++;
            }

            ////set current date to be written as excel file name
            //FileName fileName = new FileName()
            //{
            //    currentDate = currentDate,
            //    currentUser = currentUser,
            //    excelPath = excelPath
            //};

            //MyExcel.saveExcelFile(fileName);


            cd.Navigate().Back();
            r = cd.FindElement(By.XPath(".//*[@id='logout']"));
            r.Click();



            System.Threading.Thread.Sleep(10000);
            new WebDriverWait(cd, TimeSpan.FromSeconds(120));
            new WebDriverWait(cd, TimeSpan.FromSeconds(60)).Until(ExpectedConditions.ElementExists((By.XPath(".//*[@id='userid']"))));
            cd.Close();
            System.Threading.Thread.Sleep(10000);
            cd.Quit();
        }
        /// <summary>
        ///     Entry point for the scraper.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ChromeOptions options = new ChromeOptions();


            // Create instance of web scraper
            using (var db = new StockDatabase())
                using (IWebDriver webDriver = new ChromeDriver(options))
                {
                    // TODO: Suppress not working
                    // Suppress certificate errors
                    //options.AddArgument("--ignore-certificate-errors");
                    //options.AddArgument("--ignore-ssl-errors");
                    webDriver.Navigate().GoToUrl("https://finance.yahoo.com");

                    // define an explicit wait
                    WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(30));

                    // SIGN IN PROCESS
                    wait.Until <IWebElement>(d => d.FindElement(By.Id("uh-signedin")));
                    webDriver.FindElement(By.Id("uh-signedin")).Click();

                    // Sign in using email and password

                    wait.Until <IWebElement>(d => d.FindElement(By.Id("login-username")));
                    IWebElement email = webDriver.FindElement(By.Id("login-username"));
                    email.SendKeys("*****@*****.**");
                    webDriver.FindElement(By.XPath("//*[@id=\"login-signin\"]")).Click();

                    wait.Until <IWebElement>(d => d.FindElement(By.Id("login-passwd")));
                    IWebElement password = webDriver.FindElement(By.Id("login-passwd"));
                    password.SendKeys("thisisnew1234");
                    webDriver.FindElement(By.Id("login-signin")).Click();


                    // Deal with potential pop-up
                    webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
                    IList <IWebElement> popUps = webDriver.FindElements(By.XPath("//*[@id=\"__dialog\"]/section"));

                    if (popUps.Count != 0)
                    {
                        IWebElement popUpExit = webDriver.FindElement(By.XPath("//*[@id=\"__dialog\"]/section"));
                        popUpExit.Click();
                    }

                    // Navigate to Portfolio
                    webDriver.FindElement(By.XPath("//*[@id=\"Nav-0-DesktopNav\"]/div/div[3]/div/div[1]/ul/li[2]/a")).Click();
                    webDriver.FindElement(By.XPath("//*[@id=\"Col1-0-Portfolios-Proxy\"]/main/table/tbody/tr[1]/td[1]/a")).Click();

                    webDriver.Manage().Window.Maximize();

                    // TODO : Get rid of this line
                    webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);

                    // GRABBING STOCKS
                    // Grab all stocks
                    IList <IWebElement> tempTable = webDriver.FindElements(By.XPath("//*[@id=\"pf-detail-table\"]/div[1]/table/tbody")); // cannot find this same Xpath again for some reason

                    IWebElement stockTable =
                        webDriver.FindElement(By.XPath("//*[@id=\"pf-detail-table\"]/div[1]/table/tbody"));

                    IList <IWebElement> stockList = stockTable.FindElements(By.TagName("tr"));

                    int numberOfRows = stockList.Count;

                    IWebElement firstRow = webDriver.FindElement(By.XPath("//*[@id=\"pf-detail-table\"]/div[1]/table/tbody/tr[1]"));

                    // TODO : Get rid of this line
                    webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
                    int numberOfColumns             = firstRow.FindElements(By.TagName("td")).Count;
                    IList <IWebElement> currentRows = firstRow.FindElements(By.TagName("td"));

                    var messagePrinter = new StockProcesser();

                    messagePrinter.WriteVisibleConsoleMessage("stock table");
                    messagePrinter.WriteVisibleConsoleMessage(numberOfRows);
                    messagePrinter.WriteVisibleConsoleMessage(numberOfColumns);

                    // PROCESS STOCKS

                    StockProcesser stockProcessor = new StockProcesser();

                    // XPath elements start at 1 index
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    for (int i = 1; i < numberOfRows; i++)
                    {
                        var tempStock = new StockObject();
                        tempStock.ScrapeTime = DateTime.Now.ToString("G");

                        messagePrinter.WriteVisibleConsoleMessage("new stock");
                        // Last two columns are not needed, subtract 1
                        for (int j = 1; j < numberOfColumns - 1; j++)
                        {
                            //string currentText = webDriver.FindElement( By.XPath("//*[@id=\"pf-detail-table\"]/div[1]/table/tbody/tr[1]") ).Text;
                            string currentText = webDriver.FindElement(By.XPath($"//*[@id=\"pf-detail-table\"]/div[1]/table/tbody/tr[{i}]/td[{j}]")).Text;
                            stockProcessor.AddEntry(ref tempStock, currentText, j);
                            Console.WriteLine($"{j} --> {currentText}");
                        }

                        stockProcessor.listOfStocks.Add(tempStock);
                    }

                    Console.ResetColor();

                    messagePrinter.WriteVisibleConsoleMessage("check stock objects");

                    foreach (var stock in stockProcessor.listOfStocks)
                    {
                        Console.WriteLine(stock.Symbol);
                        Console.WriteLine(stock.LastPrice);
                        Console.WriteLine(stock.PercentChange);
                        Console.WriteLine(stock.Currency);
                        Console.WriteLine(stock.MarketTime);
                        Console.WriteLine(stock.MarketCap);
                    }


                    // Put stocks in database
                    foreach (var stock in stockProcessor.listOfStocks)
                    {
                        db.StockObjects.Add(stock);
                        db.SaveChanges();
                    }

                    // Get stocks from database and print
                    var query = from stock in db.StockObjects
                                orderby stock.Symbol
                                select stock;

                    messagePrinter.WriteVisibleConsoleMessage("all stock messages");

                    foreach (var stock in query)
                    {
                        Console.WriteLine("SYMBOL " + stock.Symbol);
                        Console.WriteLine("LAST PRICE " + stock.LastPrice);
                        Console.WriteLine("AVERAGE VOLUME 3M " + stock.AverageVolume3M);
                    }
                }
        }