Exemplo n.º 1
2
        public void Login(String loginUrl)
        {
            var options = new ChromeOptions();
            options.AddArguments("--test-type", "--start-maximized");
            options.AddArguments("--test-type", "--ignore-certificate-errors");
            options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
            driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);

            driver.Navigate().GoToUrl(loginUrl);

            int timeout = 0;
            while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
            {
                Thread.Sleep(1);
                timeout++;

            }

            IWebElement element = driver.FindElement(By.ClassName("logbox"));

            IWebElement ElName = element.FindElement(By.Name("username"));
            ElName.Clear();
            ElName.SendKeys(loginName);
            IWebElement ElPassword = element.FindElement(By.Id("password"));
            ElPassword.Clear();
            ElPassword.SendKeys(loginPassword);
            IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
            ElLogin.Click();
        }
Exemplo n.º 2
1
        public GrindaModel(string username, string password, BackgroundWorker bw, bool openGrinda)
        {
            string numbers = "";

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

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

            IWebDriver driver = new ChromeDriver(service, options);
            driver.Navigate().GoToUrl("http://www.grindabuck.com/login");

            try
            {
                driver.FindElement(By.Id("login_username")).SendKeys(username);
                driver.FindElement(By.Id("pwd")).SendKeys(password);

                driver.FindElement(By.ClassName("btn-lg")).Click();
            }
            catch { }

            IList<IWebElement> smalls = driver.FindElements(By.TagName("small"));
            foreach (IWebElement small in smalls)
            {
                if (small.Text.Contains("Last Checkin"))
                {
                    numbers = small.Text;
                    break;
                }
            }

            if (DateTime.Parse(numbers.Split(' ')[2]).DayOfYear != DateTime.Now.DayOfYear)
            {
                checkIn(driver);
            }
        }
Exemplo n.º 3
1
        public ZoomModel(string username, string password, BackgroundWorker bw, bool justZoom)
        {
            bool looping = true;
            while (looping)
            {

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

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

                    IWebDriver driver = new ChromeDriver(service, options);
                    driver.Navigate().GoToUrl("http://members.grabpoints.com/#/login?email=" + username);

                    try
                    {
                        //driver.FindElement(By.Name("email")).SendKeys(username);
                        //driver.FindElement(By.Name("email")).SendKeys(Keys.Enter);
                        ////Helpers.wait(5000);
                        driver.FindElement(By.Id("password")).SendKeys(password);
                        driver.FindElement(By.ClassName("btn-block")).Click();
                    }
                    catch { }

                    Helpers.wait(10000);
                if (!justZoom)
                {

                    try
                    {
                        int counter = 0;
                        IList<IWebElement> turnOffNotifcations = driver.FindElements(By.ClassName("btn-block"));
                        foreach (IWebElement turnOffNotication in turnOffNotifcations)
                        {
                            if (counter == turnOffNotifcations.Count - 1)
                            {
                                turnOffNotication.Click();
                            }
                            counter++;
                        }
                    }
                    catch { }

                    int hr = DateTime.Now.Hour;

                    try
                    {
                        driver.Navigate().GoToUrl("http://members.grabpoints.com/#/offers/watch_videos");
                    }
                    catch { }

                    while (!viroolBool)
                    {
                        try
                        {
                            System.Collections.ObjectModel.ReadOnlyCollection<string> windowHandles = driver.WindowHandles;

                            foreach (String window in windowHandles)
                            {
                                try
                                {
                                    IWebDriver popup = driver.SwitchTo().Window(window);
                                }
                                catch { }

                                try
                                {
                                    if (driver.Title.Contains("Facebook"))
                                    {
                                        driver.Close();
                                    }
                                }
                                catch { }

                                try
                                {
                                    IList<IWebElement> surveys = driver.FindElements(By.ClassName("btn-block"));
                                    if (surveys.Count > 2)
                                    {
                                        driver.FindElement(By.ClassName("btn-block")).Click();
                                    }
                                }
                                catch { }

                                if (!junVideos)
                                    junVids(driver);
                                if (!volume)
                                    volume11(driver);
                                if (volume && junVideos && !viroolBool)
                                    virool(driver);
                                Helpers.wait(5000);
                            }
                        }
                        catch { }
                    }

                    Helpers.closeWindows(driver, titles);
                    driver.Close();
                    driver.Quit();

                    hr = DateTime.Now.Hour;

                    while (DateTime.Now.Hour == hr)
                    { }
                    junVideos = false;
                    volume = false;
                    viroolBool = false;
                }
                else
                {
                    looping = false;
                }
            }
        }
Exemplo n.º 4
0
        public void Cannot_Register_User_With_Empty_Username()
        {
            string chromeDriverDirectory = string.Format(@"{0}\..\..\..\tools", Directory.GetCurrentDirectory());

            IWebDriver driver = new ChromeDriver(chromeDriverDirectory);
            driver.Navigate().GoToUrl("http://*****:*****@ssw0rd");

            IWebElement confirmPassword = driver.FindElement(By.Id("ConfirmPassword"));
            confirmPassword.SendKeys("P@ssw0rd");

            IWebElement registerButton = driver.FindElement(By.ClassName("btn"));
            registerButton.Click();

            ReadOnlyCollection<IWebElement> errorMessages = driver.FindElements(By.XPath("//div[@class='validation-summary-errors']/ul/li"));

            IWebElement errorMessage = errorMessages.FirstOrDefault();

            Assert.IsNotNull(errorMessage);
            Assert.AreEqual("The User name field is required.", errorMessage.Text);

            driver.Quit();
        }
Exemplo n.º 5
0
        Chrome.ChromeDriver wbb; // = new Chrome.ChromeDriver();
        private void getFileList_Cloud()
        {
            Thread.Sleep(200);
            var frame = wbb.FindElementByName("mainframe");
            var link  = frame.GetAttribute("src");

            //wbb.Url = getHost(wbb.Url) + "/" + link;
            wbb.Url = link;
            Thread.Sleep(200);
            var foldListElem  = wbb.FindElementById("sub_folder_list");
            var foldNameElems = foldListElem.FindElements(By.ClassName("f_name2"));
            var foldNames     = foldNameElems.Select(x => x.Text);

            ///var fileElems1 = wbb.FindElementById("filelist");
            var fileElems = wbb.FindElements(By.XPath("//div[@id='filelist']/div[@class='f_tb']"));
            var fileInfos = new List <FileInfo>();

            foreach (var x in fileElems)
            {
                FileInfo inf = new FileInfo();
                inf.name = x.FindElement(By.XPath("./div[@class='f_name']/a")).Text;
                inf.size = x.FindElement(By.CssSelector("div.f_size")).Text;
                fileInfos.Add(inf);
            }
            //this.Title = fileInfos.First().name;
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver("C:\\");
            driver.Navigate().GoToUrl("file:///C:/Users/anil.krishnamaneni/Desktop/New%20Text%20Document.html");

            var coll = driver.FindElements(By.TagName("label"));
            foreach (var label in coll)
            {
                if (label.Text.Trim() == "welcome to Ding")
                {
                    label.Click();
                    break;
                }
            }

            var alert = driver.WaitGetAlert();

            IAlert a = driver.SwitchTo().Alert();
            a.Accept();

            driver.FindElement(By.TagName("Input")).Click();
            a = driver.SwitchTo().Alert();
            a.Accept();
            driver.FindElement(By.ClassName("submit")).Click();
            a = driver.SwitchTo().Alert();
            a.Accept();
        }
Exemplo n.º 7
0
		public void Search_BestValue()
		{
			IWebDriver driver = new ChromeDriver();
			
			driver.Navigate().GoToUrl("http://www.markandspencer.com");
			
            IWebElement globalSearch = driver.FindElement(By.Id("global-search"));
			globalSearch.SendKeys("Malbec");
			globalSearch.SendKeys(Keys.Enter);
			
			IList<IWebElement> elements = driver.FindElements(By.Xpath("//dd[@class='price1']"));
			
			string price = ""; 
			double min = Double.parseDouble(elements[0].getText().replace("£","").replace(",",""));
			foreach (IWebElement child in elements)
			{
				price = child.getText().replace("£","").replace(",","");
				double childPrice = Double.parseDouble(price);
				if(childPrice < min)
				{
					min = childPrice;
				}
			}
			
			System.out.println("best value wine: " + min);
			driver.Quit();
		}
Exemplo n.º 8
0
Arquivo: Program.cs Projeto: Tunyaa/s
        static void Main(string[] args)
        {
            IWebDriver web = new OpenQA.Selenium.Chrome.ChromeDriver();

            web.Manage().Window.Maximize();

            web.Navigate().GoToUrl("https://market.yandex.ru/catalog--mototsikly/54885/list?hid=90498&onstock=1&local-offers-first=0");

            string[] chkOpt = new string[6] {
                "Honda", "BMW", "YAMAHA", "жидкостное", "6", "Гарантия производителя"
            };
            IList <IWebElement> chkBtn_Prod = web.FindElements(By.ClassName("NVoaOvqe58"));
            int iSize = chkBtn_Prod.Count();

            for (int i = 0; i < iSize; i++)
            {
                string value = chkBtn_Prod.ElementAt(i).Text;

                for (int j = 0; j < chkOpt.Length; j++)
                {
                    if (value.Equals(chkOpt[j]))
                    {
                        chkBtn_Prod.ElementAt(i).Click();
                    }
                }
            }
            Task.Delay(3000).Wait();
            //web.Quit();
            Console.ReadLine();
        }
Exemplo n.º 9
0
        public List<string> GetSearchResultProductNunmbers(ChromeDriver driver)
        {
            var Products = new List<string>();

            foreach (var nameEl in driver.FindElements(By.XPath("//img[@class='product-image']")))
            {
                Products.Add(nameEl.GetAttribute("alt").Split(' ').Last());
            }

            return Products;
        }
Exemplo n.º 10
0
		public void Search_FiveStarsRating()
		{
			IWebDriver driver = new ChromeDriver();
			
			driver.Navigate().GoToUrl("http://www.markandspencer.com");
			
            IWebElement globalSearch = driver.FindElement(By.Id("global-search"));
			globalSearch.SendKeys("Malbec");
			globalSearch.SendKeys(Keys.Enter);
			
			IList<IWebElement> elements = driver.FindElements(By.Xpath("//span[@itemprop='ratingValue' and contains(@style,'width:100.0%')]"));
			
			int fiveStars = elements.Count;//number of wines with 5 star ratings
			System.out.println("number of wines with 5 star ratings: " + fiveStars);
			driver.Quit();
		}
Exemplo n.º 11
0
		public void Search_NumberOfMalbec()
		{
			IWebDriver driver = new ChromeDriver();
			
			driver.Navigate().GoToUrl("http://www.markandspencer.com");
			
            IWebElement globalSearch = driver.FindElement(By.Id("global-search"));// with "inspect element" I pick the "id" of the element
			globalSearch.SendKeys("Malbec");
			globalSearch.SendKeys(Keys.Enter);
			
			IList<IWebElement> elements = driver.FindElements(By.Xpath("//h3[@class='body2' and contains(text()='Malbec')]"));
			
			int malbecWines = elements.Count;//number of wines returned for a search on the word “malbec”
			System.out.println("number of Malbec wines: " + malbecWines);
			driver.Quit();
		}
Exemplo n.º 12
0
 public void SuccessfulLogin()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--no-sandbox");
     options.AddArgument("--disable-extensions");
     options.AddArgument("--start-maximized");
     IWebDriver driver = new ChromeDriver(options);
     driver.Navigate().GoToUrl("http://www.qa.way2automation.com/");
     driver.FindElement(By.CssSelector("#load_form > h3"));
     driver.FindElement(By.CssSelector("#load_form > div > div.span_3_of_4 > p > a[href='#login']")).Click();
     driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(5) > input[name='username']")).SendKeys("j2bwebdriver");
     driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(6) > input[name='password']")).SendKeys("j2bwebdriver");
     driver.FindElements(By.CssSelector("#load_form > div > div.span_1_of_4 > input"))[1].Submit();
     Thread.Sleep(3000);
     Assert.IsFalse(driver.FindElement(By.CssSelector("body")).Text.Contains("Username"));
     Assert.IsFalse(driver.FindElement(By.CssSelector("body")).Text.Contains("Password"));
     driver.Close();
 }
Exemplo n.º 13
0
         public static void SetData(int marketId,string linkText,bool isGoOn, int priceIndex)
         { 
            IWebDriver driver = new ChromeDriver();
            try
            {
                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://www.f139.com/");

                var loginName = driver.FindElement(By.Id("userName"));
                loginName.SendKeys("zh15295667405");
                var loginPassword = driver.FindElement(By.Id("passWord"));
                loginPassword.SendKeys("15295667405");
                var loginBtn = driver.FindElement(By.ClassName("btn_login"));
                loginBtn.Click();

                var ferroalloyUrls = driver.FindElements(By.LinkText("废钢网"));
                driver.Navigate().GoToUrl(ferroalloyUrls[0].GetAttribute("href"));
                Thread.Sleep(2000);

                var silicon = driver.FindElement(By.LinkText("数据"));
                driver.Navigate().GoToUrl(silicon.GetAttribute("href"));
                Thread.Sleep(2000);

                var gc = driver.FindElement(By.LinkText("钢材"));
                driver.Navigate().GoToUrl(gc.GetAttribute("href"));
                Thread.Sleep(2000);

                var linkName = driver.FindElement(By.LinkText(linkText));
                driver.Navigate().GoToUrl(linkName.GetAttribute("href"));
                Thread.Sleep(2000);

                GetData(driver, marketId, isGoOn, priceIndex);

                foreach (Price price in PriceList)
                {
                    PriceHelper.SavePrice(price);
                }
            }
            finally
            {
                driver.Close();
                driver.Quit();
            }
         }
Exemplo n.º 14
0
         //冶金焦、铸造焦
         public void Run()
         { 
            IWebDriver driver = new ChromeDriver();
            try
            {
                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://data.f139.com/list.do?pid=3&vid=126");

                var loginNames = driver.FindElements(By.Id("userName"));
                if(loginNames.Count > 0)
                {
                    var loginName = loginNames[0];
                    loginName.SendKeys("zh15295667405");
                    var loginPassword = driver.FindElement(By.Id("passWord"));
                    loginPassword.SendKeys("15295667405");
                    var loginBtn = driver.FindElement(By.Id("submitbtn"));
                    loginBtn.Click();
                }
                var divP = driver.FindElement(By.Id("thjprolist"));
                var divs = divP.FindElements(By.TagName("div"));
                var yCokeDiv = divs[8].FindElement(By.LinkText("冶金焦"));//冶金焦链接
                //var zCokeDiv = divs[8].FindElement(By.LinkText("铸造焦"));//铸造焦链接
                driver.Navigate().GoToUrl(yCokeDiv.GetAttribute("href"));
                GetData(driver);
                var divPz = driver.FindElement(By.Id("thjprolist"));
                var divSz = divPz.FindElements(By.TagName("div"));
                var zCokeDiv = divSz[8].FindElement(By.LinkText("铸造焦"));//铸造焦链接
                driver.Navigate().GoToUrl(zCokeDiv.GetAttribute("href"));
                GetData(driver);

                foreach(Price price in PriceList)
                {
                    PriceHelper.SavePrice(price);
                }
            }
            finally {
                driver.Close();
                driver.Quit();
            }
         }
Exemplo n.º 15
0
        public void Login()
        {
            var options = new ChromeOptions();
            DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
            capabilities.SetCapability("chrome.switches", (object)("--start-maxisized"));
            options.AddArguments("--test-type", "--start-maximized");
            options.AddArguments("--test-type", "--ignore-certificate-errors");
            options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
            var driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);

            //var ieoptions = new InternetExplorerOptions();
            //DesiredCapabilities iecapabilities = DesiredCapabilities.InternetExplorer();
            //iecapabilities.SetCapability("internetexplorer.switches", (object)("--start-maxisized"));
            //ieoptions.AddAdditionalCapability("--test-type", "--start-maximized");
            //ieoptions.AddAdditionalCapability("--test-type", "--ignore-certificate-errors");
            //var iedriver = new InternetExplorerDriver(@"C:\Program Files (x86)\Internet Explorer");

            driver.Navigate().GoToUrl(loginurl);

            int timeout = 0;
            while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
            {
                Thread.Sleep(1);
                timeout++;

            }

            IWebElement element = driver.FindElement(By.ClassName("logbox"));

            IWebElement ElName = element.FindElement(By.Name("username"));
            ElName.Clear();
            ElName.SendKeys(loginName);
            IWebElement ElPassword = element.FindElement(By.Id("password"));
            ElPassword.Clear();
            ElPassword.SendKeys(loginPassword);
            IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
            ElLogin.Click();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            //IWebDriver driver = new FirefoxDriver();
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("http://www.thetestroom.com/webapp");

            // step to interact with the browser
            driver.FindElement(By.Id("contact_link")).Click();
            System.Threading.Thread.Sleep(1000);
            driver.FindElement(By.Name("name_field")).SendKeys("I will subscribe to this channel");
            driver.FindElement(By.Name("address_field")).SendKeys("Please like this video");

            IList<IWebElement> links = driver.FindElements(By.TagName("a"));

            foreach(IWebElement link in links)
            {
                if (link.Text.Equals("ABOUT"))
                {
                    link.Click();
                    break;
                }
            }
            //driver.Quit();
        }
Exemplo n.º 17
0
        public PedModel(string username, string password, BackgroundWorker bw, bool openPed)
        {
            ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
            service.HideCommandPromptWindow = true;

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

            IWebDriver driver = new ChromeDriver(service, options);
            driver.Navigate().GoToUrl("http://www.pedtoclick.com/index.php?view=login");

            try
            {
                driver.FindElement(By.Name("username")).SendKeys(username);
                driver.FindElement(By.Name("password")).SendKeys(password);
                driver.FindElement(By.Name("password")).SendKeys(Keys.Enter);
            }
            catch { }
            finally { }
            Helpers.ByClass(driver, "login");

            Helpers.wait(5000);
            if (!openPed)
            {
                driver.Navigate().GoToUrl("http://www.pedtoclick.com/superRewards.php");

                Helpers.wait(10000);

                IList<IWebElement> iframes = driver.FindElements(By.TagName("iframe"));
                foreach (IWebElement iframe in iframes)
                {
                    Debug.WriteLine(iframe.Text);
                }

                Helpers.switchToBrowserByString(driver, "PEDtoClick");
                Helpers.switchFrameByNumber(driver, 0);
                try
                {
                    IList<IWebElement> lis = driver.FindElements(By.TagName("li"));
                    Debug.WriteLine(lis.Count);
                    IList<IWebElement> navOptions = driver.FindElements(By.ClassName("nav-option"));
                    Debug.WriteLine(navOptions.Count);
                }
                catch { }

                Helpers.switchToBrowserByString(driver, "PEDtoClick");
                Helpers.switchFrameByNumber(driver, 1);
                try
                {
                    IList<IWebElement> lis = driver.FindElements(By.TagName("li"));
                    Debug.WriteLine(lis.Count);
                    IList<IWebElement> navOptions = driver.FindElements(By.ClassName("nav-option"));
                    Debug.WriteLine(navOptions.Count);
                }
                catch { }

                Helpers.switchToBrowserByString(driver, "PEDtoClick");
                Helpers.switchFrameByNumber(driver, 2);
                try
                {
                    IList<IWebElement> lis = driver.FindElements(By.TagName("li"));
                    Debug.WriteLine(lis.Count);
                    IList<IWebElement> navOptions = driver.FindElements(By.ClassName("nav-option"));
                    Debug.WriteLine(navOptions.Count);
                    driver.FindElement(By.LinkText("Video")).Click();

                    Helpers.wait(5000);

                    try
                    {
                        IList<IWebElement> h2s = driver.FindElements(By.TagName("h2"));
                        foreach (IWebElement h2 in h2s)
                        {
                            if (h2.Text.Contains("HyprMX"))
                            {
                                h2.Click();
                                superRewards(driver);
                            }
                        }
                    }
                    catch { }
                }
                catch { }

            }
        }
Exemplo n.º 18
0
        //硅铬
        public void Run()
        {
            IWebDriver driver = new ChromeDriver();
            try
            {
                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://www.f139.com/");

                var loginName = driver.FindElement(By.Id("userName"));
                loginName.SendKeys("f13853998584");
                var loginPassword = driver.FindElement(By.Id("passWord"));
                loginPassword.SendKeys("138539");
                var loginBtn = driver.FindElement(By.ClassName("btn_login"));
                loginBtn.Click();

                var ferroalloyUrls = driver.FindElements(By.LinkText("铁合金网"));
                driver.Navigate().GoToUrl(ferroalloyUrls[0].GetAttribute("href"));
                Thread.Sleep(2000);

                var silicon = driver.FindElement(By.LinkText("铬系"));
                driver.Navigate().GoToUrl(silicon.GetAttribute("href"));
                Thread.Sleep(2000);

                var demosticPrice = driver.FindElement(By.LinkText("国内价格"));
                driver.Navigate().GoToUrl(demosticPrice.GetAttribute("href"));
                Thread.Sleep(2000);

                var date = DateTime.Now.GetDateTimeFormats('M')[0].ToString();
                var ferrosilicons = driver.FindElements(By.LinkText(date + "国内主要地区硅铬市场价格汇总"));
                if (ferrosilicons.Count > 0)
                {
                    driver.Navigate().GoToUrl(ferrosilicons[0].GetAttribute("href"));
                    Thread.Sleep(2000);

                    var dateSpan = driver.FindElement(By.ClassName("cGray")).Text;
                    var infoparts = dateSpan.Split(new[] { "   " }, StringSplitOptions.RemoveEmptyEntries);
                    var pubTimeStr = infoparts[0];
                    DateTime pdate;
                    if (!DateTime.TryParse(pubTimeStr, out pdate))
                    {
                        pdate = DateTime.Now;
                    }
                    var zwDiv = driver.FindElement(By.Id("zhengwen"));
                    var table = zwDiv.FindElement(By.TagName("table"));
                    var trs = table.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr"));
                    var firstTds = trs[0].FindElements(By.TagName("th"));
                    var titleTxt = firstTds[3].Text.Trim();//获取含有单位title的文本
                    var unit = titleTxt.Substring(titleTxt.IndexOf("(") + 1, titleTxt.IndexOf(")") - (titleTxt.IndexOf("(") + 1));//单位
                    List<Price> pList = new List<Price>();

                    for (int i = 1; i < trs.Count; i++)
                    {
                        var p = new Price
                        {
                            Date = pdate,
                            PriceUnit = unit,
                            MarketCrmId = MarketId
                        };

                        var tds = trs[i].FindElements(By.TagName("td"));//找到一行数据的所有列
                        var tags = new string[3];//把价格列之前的所有数据用|隔开组成一个字符串
                        for (int j = 0; j < 3; j++)
                        {
                            tags[j] = tds[j].Text;
                        }
                        string token = "|" + String.Join("|", tags) + "|";
                        p.Token = token;

                        var priceStr = tds[3].Text.Trim();//找到价格列的值
                        if (string.IsNullOrEmpty(priceStr) || priceStr == "-")
                        {
                            p.HPirce = null;
                            p.LPrice = null;
                        }
                        else
                        {
                            if (priceStr.Contains("-"))
                            {
                                int ind = priceStr.IndexOf("-");
                                if (ind > 0)
                                {
                                    var priceL = priceStr.Substring(0, ind);//最低价
                                    var priceH = priceStr.Substring(ind + 1);//最高价
                                    p.LPrice = decimal.Parse(priceL);
                                    p.HPirce = decimal.Parse(priceH);
                                }
                            }
                            else
                            {
                                decimal price;
                                if (!decimal.TryParse(priceStr, out price))
                                {
                                    p.HPirce = null;
                                    p.LPrice = null;
                                }
                                else
                                {
                                    p.LPrice = price;
                                    //p.HPirce = price;
                                }
                            }
                        }

                        var tdDelta = tds[4].Text.Trim();//涨跌
                        if (!string.IsNullOrEmpty(tdDelta))
                        {
                            var firstTxt = tdDelta.Substring(0, 1);
                            if (firstTxt == "涨")
                            {
                                p.Delta = decimal.Parse(tdDelta.Substring(1));
                            }
                            else if (firstTxt == "跌")
                            {
                                p.Delta = -decimal.Parse(tdDelta.Substring(1));
                            }
                            else if (firstTxt == "平")
                            {
                                p.Delta = null;
                            }
                        }
                        else
                        {
                            p.Delta = null;
                        }

                        if (p.HPirce.HasValue && p.LPrice.HasValue)
                        {
                            p.Spread = (p.HPirce.Value + p.LPrice.Value) / 2;
                        }

                        pList.Add(p);
                        if (p.Token == "|四川|Si+Cr≥72%,C≤0.1%|硅铬|")
                        {
                            var jsPrice = new Price
                            {
                                Token = "|江苏|Si+Cr≥72%,C≤0.1%|硅铬|",
                                PriceUnit = p.PriceUnit,
                                MarketCrmId = p.MarketCrmId,
                                Date = p.Date,
                                HPirce = p.HPirce,
                                LPrice = p.LPrice,
                                Delta = p.Delta,
                                Spread = p.Spread
                            };
                            var zjPrice = new Price {
                                Token = "|浙江|Si+Cr≥72%,C≤0.1%|硅铬|",
                                PriceUnit = p.PriceUnit,
                                MarketCrmId = p.MarketCrmId,
                                Date = p.Date,
                                HPirce = p.HPirce,
                                LPrice = p.LPrice,
                                Delta = p.Delta,
                                Spread = p.Spread
                            };
                            pList.Add(jsPrice);
                            pList.Add(zjPrice);
                        }
                    }

                    foreach (Price price in pList)
                    {
                        PriceHelper.SavePrice(price);
                    }
                }
            }
            finally
            {
                driver.Close();
                driver.Quit();
            }
        }
Exemplo n.º 19
0
        private static void Main(string[] args)
        {
            //var arg0 = @"C:\temp\Dropbox\jnk\WeSellCars\"; // file path
            //var arg1 = @"C:\git\apdekock.github.io\"; //repo path
            //var arg2 = @"_posts\2015-08-04-weMineData.markdown"; //post path
            //var arg3 = @"C:\Program Files\Git\cmd\git.exe"; //git path

            try
            {
                StringBuilder listOfLines = new StringBuilder();
                var chromeOptions = new ChromeOptions();
                chromeOptions.AddArguments("-incognito");
                using (IWebDriver driver = new ChromeDriver(Path.Combine(Directory.GetCurrentDirectory(), "WebDriverServer"), chromeOptions))
                {
                    driver.Navigate().GoToUrl("http://www.wesellcars.co.za/vehicle/category/all");
                    var findElement = driver.FindElements(By.CssSelector("#main_content > div > div.vehicles.grid > div.item"));

                    foreach (var item in findElement)
                    {
                        var image = item.FindElement(By.CssSelector("a"));
                        var link = image.GetAttribute("href");
                        var lines =
                            new List<string>(item.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
                            {
                                link
                            };
                        var format = string.Join(",", lines);
                        listOfLines.AppendLine(format);
                        Console.WriteLine(format);
                    }

                    driver.Quit();
                }

                var cTempCarsTxt = args[0] + @"\WeSellCars_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".csv";
                var fileStream = File.Create(cTempCarsTxt);
                fileStream.Close();
                File.WriteAllText(cTempCarsTxt, listOfLines.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            StringBuilder postTemplate = new StringBuilder();
            postTemplate.AppendLine("---");
            postTemplate.AppendLine("layout: post ");
            postTemplate.AppendLine("title: \"Scraping and GitSharp, and Spark lines\" ");
            postTemplate.AppendLine("date: 2016-08-07");
            postTemplate.AppendLine(
                "quote: \"If you get pulled over for speeding. Tell them your spouse has diarrhoea. — Phil Dunphy [Phil’s - osophy]\"");
            postTemplate.AppendLine("categories: scraping, auto generating post, gitsharp");
            postTemplate.AppendLine("---");
            postTemplate.AppendLine(
                string.Format(
                    "This page is a daily re-generated post (last re-generated  **{0}**), that shows the movement of prices on the [www.weSellCars.co.za](http://www.wesellcars.co.za) website.",
                    DateTime.Now));
            postTemplate.AppendLine("");
            postTemplate.AppendLine("## Why?");
            postTemplate.AppendLine("");
            postTemplate.AppendLine(
                "This post is the culmination of some side projects I've been playing around with. Scraping, looking for a way to integrate with git through C# and a challenge to use this blog (which has no back-end or support for any server side scripting) to dynamically update a post. I realise that would best be accomplished through just making new posts but I opted for an altered post as this is a tech blog, and multiple posts about car prices would not be appropriate.");
            postTemplate.AppendLine("");
            postTemplate.AppendLine("# Lessons learned");
            postTemplate.AppendLine("");
            postTemplate.AppendLine(
                "* [GitSharp](http://www.eqqon.com/index.php/GitSharp) is limited and I needed to grab the project from [github](https://github.com/henon/GitSharp) in order to use it.");
            postTemplate.AppendLine(
                "    The NuGet package kept on complaining about a **repositoryformatversion** setting in config [Core] that it required even though it was present, it still complained. So, I downloaded the source to debug the issue but then I did not encounter it. Apart from that - gitsharp did not allow me to push - and it seems the project does not have a lot of contribution activity (not criticising, just stating. I should probably take this up and contribute, especially as I would like to employ git as a file store for an application. Levering off the already refined functions coudl be a win but more on that in another post).");
            postTemplate.AppendLine(
                "* Scraping with Selenium is probably not the best way - rather employ [HttpClient](https://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.118).aspx).");
            postTemplate.AppendLine(
                "* For quick, easy and painless sparklines [jQuery Sparklines](http://omnipotent.net/jquery.sparkline/#s-about)");
            postTemplate.AppendLine(
                "* No backend required, just a simple process running on a server, that commits to a repo (ghPages) gets the job done.");

            postTemplate.AppendLine("");
            var aggregateData = new AggregateData(new FileSystemLocation(args[0]));
            var dictionary = aggregateData.Aggregate();

            var html = aggregateData.GetHTML(dictionary);
            if (dictionary.Count > 0)
            {
                postTemplate.AppendLine("## The List");
            }
            postTemplate.AppendLine(html);

            // update post file
            FileInfo fi = new FileInfo(args[1] + args[2]);
            var streamWriter = fi.CreateText();
            streamWriter.WriteLine(postTemplate.ToString());

            streamWriter.Flush();
            streamWriter.Dispose();

            Repository repository = new Repository(args[1]);

            repository.Index.Add(args[1] + args[2]);
            Commit commited = repository.Commit(string.Format("Updated {0}", DateTime.Now),
                new Author("Philip de Kock", "*****@*****.**"));
            if (commited.IsValid)
            {
                string gitCommand = args[3];
                const string gitPushArgument = @"push origin";
                ProcessStartInfo psi = new ProcessStartInfo(gitCommand, gitPushArgument)
                {
                    WorkingDirectory = args[1],
                    UseShellExecute = true
                };
                Process.Start(psi);
            }
        }
Exemplo n.º 20
0
         public static void GetData(string divID, string linkName, string cityName)
         {
             IWebDriver driver = new ChromeDriver();
             try
             {
                 driver.Manage().Window.Maximize();
                 driver.Navigate().GoToUrl("http://www.mysteel.com/");
                 var userName = driver.FindElement(By.Name("my_username"));
                 userName.SendKeys("tx6215");
                 var password = driver.FindElement(By.Name("my_password"));
                 password.SendKeys("tx6215");
                 userName.Submit();

                 var hsteel = driver.FindElement(By.LinkText("硅钢"));
                 driver.Navigate().GoToUrl(hsteel.GetAttribute("href"));
                 Thread.Sleep(2000);

                 var mDiv = driver.FindElements(By.ClassName("mRow"))[0].FindElement(By.ClassName("rRihgt")).FindElement(By.ClassName("box")).FindElement(By.Id(divID));
                 var moreLi = mDiv.FindElement(By.ClassName("more"));
                 var link = moreLi.FindElement(By.TagName("a"));
                 driver.Navigate().GoToUrl(link.GetAttribute("href"));
                 Thread.Sleep(2000);

                 var date = DateTime.Now.Day + "日";
                 var sh = driver.FindElement(By.LinkText(date + linkName));
                 if (sh != null)
                 {
                     driver.Navigate().GoToUrl(sh.GetAttribute("href"));
                     Thread.Sleep(2000);

                     var timeSpan = driver.FindElement(By.ClassName("info")).Text;
                     var timeSplit = timeSpan.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                     var pubTime = timeSplit[0];
                     DateTime pdate;
                     if (!DateTime.TryParse(pubTime, out pdate))
                     {
                         pdate = DateTime.Now;
                     }

                     var table = driver.FindElement(By.Id("text22222")).FindElement(By.TagName("table"));
                     var trs = table.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr"));
                     var firstTds = trs[0].FindElements(By.TagName("td"));
                     var titleTxt = firstTds[4].Text.Trim();
                     var unit = titleTxt.Substring(titleTxt.IndexOf("(") + 1, titleTxt.IndexOf(")") - (titleTxt.IndexOf("(") + 1));//单位

                     for (int i = 2; i < trs.Count; i++)
                     {
                         var p = new Price
                         {
                             Date = pdate,
                             PriceUnit = unit,
                             MarketCrmId = MarketId
                         };
                         var tds = trs[i].FindElements(By.TagName("td"));//找到一行数据的所有列
                         var tags = new string[4];//把价格列之前的所有数据用|隔开组成一个字符串
                         for (int j = 0; j < 4; j++)
                         {
                             tags[j] = tds[j].Text;
                         }
                         string token = "|" + cityName + "|" + String.Join("|", tags) + "|";
                         p.Token = token;

                         var priceStr = tds[4].Text.Trim();//找到价格列的值
                         if (string.IsNullOrEmpty(priceStr) || priceStr == "-")
                         {
                             p.HPirce = null;
                             p.LPrice = null;
                         }
                         else
                         {
                             if (priceStr.Contains("-"))
                             {
                                 int ind = priceStr.IndexOf("-");
                                 if (ind > 0)
                                 {
                                     var priceL = priceStr.Substring(0, ind);//最低价
                                     var priceH = priceStr.Substring(ind + 1);//最高价
                                     p.LPrice = decimal.Parse(priceL);
                                     p.HPirce = decimal.Parse(priceH);
                                 }
                             }
                             else
                             {
                                 decimal price;
                                 if (!decimal.TryParse(priceStr, out price))
                                 {
                                     p.HPirce = null;
                                     p.LPrice = null;
                                 }
                                 else
                                 {
                                     p.LPrice = price;
                                     //p.HPirce = price;
                                 }
                             }
                         }

                         var tdDelta = tds[5].Text.Trim();//涨跌
                         if (!string.IsNullOrEmpty(tdDelta) && tdDelta != "-")
                         {
                             var firstTxt = tdDelta.Substring(0, 1);
                             if (firstTxt == "+")
                             {
                                 p.Delta = decimal.Parse(tdDelta.Substring(1));
                             }
                             else if (firstTxt == "-")
                             {
                                 p.Delta = -decimal.Parse(tdDelta.Substring(1));
                             }
                         }
                         else
                         {
                             p.Delta = null;
                         }

                         if (p.HPirce.HasValue && p.LPrice.HasValue)
                         {
                             p.Spread = (p.HPirce.Value + p.LPrice.Value) / 2;
                         }

                         var desc = tds[6].Text;//备注
                         p.Comment = desc;
                         PriceHelper.SavePrice(p);
                     }
                 }

             }
             finally
             {
                 driver.Close();
                 driver.Quit();
             }
         }
Exemplo n.º 21
0
        public RebelModel(string username, string password, BackgroundWorker bw, bool openRebel)
        {
            while (true)
            {
                ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
                service.HideCommandPromptWindow = true;

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

                //if (openRebel)
                //options.AddAdditionalCapability("mobileEmulation", new Dictionary<string, string> { { "deviceName", "Google Nexus 5" } });

                IWebDriver driver = new ChromeDriver(service, options);

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

                Helpers.ByClass(driver, "ss-icon");

                try
                {
                    driver.FindElement(By.Id("loginFormEmail")).SendKeys(username);
                    driver.FindElement(By.ClassName("hero-form-first-password")).SendKeys(password);
                }
                catch { }

                Helpers.ById(driver, "loginSubmit");

                Helpers.wait(1000);

                if (!openRebel)
                {
                    driver.Navigate().GoToUrl("http://www.prizerebel.com/dailypoints.php");
                    dailyPoints(driver);
                    driver.Navigate().GoToUrl("http://www.prizerebel.com/offerwalls.php");
                    Helpers.wait(5000);

                    try
                    {
                        IList<IWebElement> virools = driver.FindElements(By.ClassName("filter-tab-btn"));
                        foreach (IWebElement virool in virools)
                        {
                            if (virool.Text == "Virool")
                            {
                                virool.Click();
                                break;
                            }
                        }
                        virool(driver);
                        videos(driver);
                    }
                    catch { }

                    driver.Navigate().GoToUrl("http://www.prizerebel.com/offerwalls.php");
                    Helpers.wait(5000);
                    try
                    {
                        IList<IWebElement> virools = driver.FindElements(By.ClassName("filter-tab-btn"));
                        foreach (IWebElement virool in virools)
                        {
                            if (virool.Text == "Encrave")
                            {
                                virool.Click();
                                break;
                            }
                        }
                        encrave(driver);
                    }
                    catch { }
                    driver.Quit();
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 22
0
        private List<string> pullGamesHelper(ChromeDriver cd)
        {
            List<string> AllYourGames = new List<string>();
            IWebElement e;
            string purchaseTitle = "";
            bool anotherRow = true;
            int index = 0;
            while (anotherRow)
            {
                index++;
                try
                {
                    e = cd.FindElementById("transactionDetailsRow-" + index);
                    e.Click();
                    System.Threading.Thread.Sleep(1000);

                    try
                    {
                        ReadOnlyCollection<IWebElement> roc = cd.FindElements(By.Id("itemTitle-0"));
                        foreach (IWebElement iwe in roc)
                        {
                            purchaseTitle = iwe.Text;
                            AllYourGames.Add(purchaseTitle);
                        }
                        cd.Navigate().Back();
                        System.Threading.Thread.Sleep(1000);
                    }
                    catch (Exception)
                    {
                        purchaseTitle = "This wasn't a game/movie";
                        cd.Navigate().Back();
                        System.Threading.Thread.Sleep(1000);
                    }
                    //AllYourGames.Add(purchaseTitle);
                }
                catch (Exception)
                {
                    Console.WriteLine("The program has finished gathering the data...");
                    anotherRow = false;
                }

            }
            cd.Close();
            cd.Dispose();
            return AllYourGames;
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            //Declaration
                //l = phone numbers, quotation number, desc of the records, entity, submission date , submission time, name of user
                List<string> l = new List<string>();
                List<string> quotation = new List<string>();
                List<string> desc = new List<string>();
                List<string> entity = new List<string>();
                List<string> subDate = new List<string>();
                List<string> subTime = new List<string>();
                List<string> name = new List<string>();
                List<string> kw = new List<string>();
                Dictionary<string, string> dict = new Dictionary<string, string>();
                int numbrecords = 0;
                string filename = "";

                #region Load google chrome
                // Initialize the Chrome Driver
                using (var driver = new ChromeDriver())
                {
                    LoadFile(ref l, ref dict);

                    // Go to the home page
                    driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");

                    #region autofill and extract data from GeBiz webpage
                    foreach (var val in l)
                    {
                        //Get the page elements

                        var fromdate = driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[2]/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[5]/td[4]/input");
                        var todate = driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[2]/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[5]/td[6]/input");
                        var keyword = driver.FindElementByName("searchByDesc");
                        new SelectElement(driver.FindElement(By.Name("dateType"))).SelectByIndex(1);
                        var submitbutton = driver.FindElementByName("submitAction");

                        fromdate.SendKeys(DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy"));
                        todate.SendKeys(DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy"));

                        keyword.SendKeys(val);

                        //click the submit button
                        submitbutton.Click();

                        if (driver.FindElements(By.XPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td")).Count == 1)
                        {
                            driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
                        }
                        else
                        {

                            if (driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td").Text.Equals("No data found"))
                            {
                                Console.WriteLine("No Data Found");
                                driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
                            }
                            else
                            {
                                #region Checking the number of records
                                for (int j = 11; j > 1; j--)
                                {
                                    //select the records by row
                                    if (driver.FindElements(By.XPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + j + "]")).Count == 1)
                                    {
                                        Console.WriteLine(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td").Text);
                                        numbrecords = j + 1;
                                        #region Storing quotation and desc to list
                                        for (int i = 2; i < numbrecords; i++)
                                        {
                                            //get the record from the current row on the quotation col
                                            quotation.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[2]/table/tbody/tr[1]/td/a/b").Text);
                                            //get the record from the current row on the description col
                                            desc.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[3]/table/tbody/tr[1]/td").Text);
                                            //get the record from the current row on entity from description col
                                            entity.Add(RemoveWord(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[3]/table/tbody/tr[2]/td").Text));
                                            //get the record from the current row on submission date from closing date/time col
                                            subDate.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[5]/table/tbody/tr[1]/td").Text);
                                            //get the record from the current row on submission time from closing date/time col
                                            subTime.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[5]/table/tbody/tr[2]/td").Text);
                                            //add the name of the organisation that the keyword belong to
                                            name.Add(dict[val]);
                                            //add the keyword
                                            kw.Add(val);
                                        }
                                        driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
                                        break;
                                        #endregion
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                    #endregion
                }
                #endregion
                //saving to excel file
                filename = SaveExcel();

                ExportData(filename, ref quotation, ref desc, ref entity, ref subDate, ref subTime, ref name, ref kw);
        }
Exemplo n.º 24
0
        private static void Test1()
        {
            driver = new ChromeDriver("C:\\Users\\User\\Desktop\\SeleniumTests\\chromedriver_win32\\");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            //going to the website
            driver.Navigate().GoToUrl("http://mirasan.ca");
            stopwatch.Stop();
            //returns how long it took for the page to load
            Console.WriteLine("The webpage took " + stopwatch.ElapsedMilliseconds + " miliseconds to load");

            stopwatch.Start();

            driver.FindElement(By.Id("LayoutHeaderSearchBox")).SendKeys("don mills");
            driver.FindElement(By.Id("LayoutHeaderSearchBox")).SendKeys(Keys.Enter);

            var timeout = new Stopwatch();
            timeout.Start();

            // waits until the results come up
            wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("aniSpriteLoadingBarSmall")));
            wait.Until<bool>(x =>
            {
                var element = x.FindElement(By.Id("LayoutHeaderSearchStatus"));
                return element.Text != "Loading" && element.Text != "Showing recently-accessed devices"
                    && element.Text != "No results";
            });

            //returns the time it took for the search
            timeout.Stop();
            Console.WriteLine("The search took: " + timeout.ElapsedMilliseconds);

            // click on dropdown menu and wait for a popup
            driver.FindElement(By.XPath("//*[@id='LayoutHeaderSearchResults']/div[2]")).Click();
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("/html/body/div[5]/div[2]/a")));

            // checks to see if there is a "More Information" button
            if (driver.FindElements(By.PartialLinkText("More Information")).Count > 0)
            {
                driver.FindElement(By.PartialLinkText("More Information")).Click();
                wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("infoPageTitleText")));

                string type;
                //figures out what kind of information we are dealling with and acts accordingly
                ActOnElement(out type);
            }

            else
            {
                //zoom in on map
            }
            stopwatch.Stop();
            Console.WriteLine("This test took: " + stopwatch.ElapsedMilliseconds);

            driver.Quit();
        }
Exemplo n.º 25
0
		public void Run()
		{
			IWebDriver driver = new ChromeDriver();
			try
			{
				
				driver.Manage().Window.Maximize();

				driver.Navigate().GoToUrl("http://list1.mysteel.com/market/p-405-----010211-0--------1.html");
				var loginNames = driver.FindElements(By.Name("my_username"));
				if (loginNames.Count > 0)
				{
					loginNames[0].SendKeys("tx6215");
					//not logined
					var loginPwds = driver.FindElements(By.Name("my_password"));
					loginPwds[0].SendKeys("tx6215");

					loginNames[0].Submit();
				}

				var d = DateTime.Today.Day;
				var ts = driver.FindElements(By.LinkText(d.ToString(CultureInfo.InvariantCulture) + "日上海市场拉丝材价格行情"));
				driver.Navigate().GoToUrl(ts[0].GetAttribute("href"));
				Thread.Sleep(2000);


				//get publish time
				var infos = driver.FindElement(By.ClassName("info")).Text;
				var infoparts = infos.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);
				var pubTimeStr = infoparts[0];

				DateTime pdt;
				if (!DateTime.TryParse(pubTimeStr, out pdt))
				{
					pdt = DateTime.Now;
				}

				var priceLines =
					driver.FindElement(By.Id("marketTable")).FindElement(By.TagName("tbody")).FindElements(By.TagName("tr"));

				for (int i = 1; i < priceLines.Count; i++)
				{
					var p = new Price
						        {
							        Date = pdt,
							        MarketCrmId = MarketId
						        };

					var fields = priceLines[i].FindElements(By.TagName("td"));
					var tags = new string[5];
					for (int j = 0; j < 5; j++)
					{
						tags[j] = fields[j].Text;
					}
					string token = "|" + String.Join("|", tags) + "|";
					p.Token = token;

					var priceStr = fields[5].Text.Trim();
					decimal priceD;
					if (string.IsNullOrWhiteSpace(priceStr) || priceStr == "-" || !decimal.TryParse(priceStr, out priceD))
					{
						p.LPrice = null;
					}
					else
					{
						p.LPrice = priceD;
					}

					var deltaStr = fields[6].Text.Trim();
					decimal deltaD;
					if (string.IsNullOrWhiteSpace(deltaStr) || priceStr == "-" || !decimal.TryParse(deltaStr, out deltaD))
					{
						p.Delta = null;
					}
					else
					{
						p.Delta = deltaD;
					}

					p.Comment = fields[7].Text.Trim();
					PriceHelper.SavePrice(p);
				}
			}
			finally
			{
				driver.Close();
				driver.Quit();
			}
			
		}
Exemplo n.º 26
0
        /// <summary>
        /// This function searches something in the search bar using query, and then selects the result based on the index. If the index invalid, it is defaulted to 1
        /// </summary>
        /// <param name="query"></param>
        /// <param name="index"></param>
        private static void SearchTest(string query, int index)
        {
            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WriteLine("The search query was: " + query);
            Console.ResetColor();

            driver = new ChromeDriver("C:\\Users\\User\\Desktop\\SeleniumTests\\chromedriver_win32\\");
            wait = new WebDriverWait(driver, TimeSpan.FromMilliseconds(10000));
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            //going to the website
            driver.Navigate().GoToUrl("http://mirasan.ca");
            stopwatch.Stop();

            //returns how long it took for the page to load
            Console.WriteLine("The webpage took " + stopwatch.ElapsedMilliseconds + " miliseconds to load");

            stopwatch.Start();

            driver.FindElement(By.Id("LayoutHeaderSearchBox")).SendKeys(query);
            driver.FindElement(By.Id("LayoutHeaderSearchBox")).SendKeys(Keys.Enter);

            var timeout = new Stopwatch();
            timeout.Start();

            // waits until the results come up
            wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("aniSpriteLoadingBarSmall")));
            wait.Until<bool>(x =>
            {
                var element = x.FindElement(By.Id("LayoutHeaderSearchStatus"));
                return element.Text != "Loading" && element.Text != "Showing recently-accessed devices";
            });

            //returns the time it took for the search
            timeout.Stop();
            Console.WriteLine("The search took: " + timeout.ElapsedMilliseconds);

            //if there are no results
            if (driver.FindElement(By.Id("LayoutHeaderSearchStatus")).Text == "No results")
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("There were no results found");
                Console.ResetColor();

                driver.Quit();
                return;
            }

            //checking for out of bounds indexes
            if (driver.FindElements(By.XPath("//*[@id='LayoutHeaderSearchResults']/div")).Count == 1)
            {
                index = 1;
            }
            else if (driver.FindElements(By.XPath("//*[@id='LayoutHeaderSearchResults']/div")).Count < index)
            {
                index = driver.FindElements(By.XPath("//*[@id='LayoutHeaderSearchResults']/div")).Count;
            }

            //Clicking on a search result
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='LayoutHeaderSearchResults']/div[" + index + "]")));
            driver.FindElement(By.XPath("//*[@id='LayoutHeaderSearchResults']/div["+ index +"]")).Click();

            // Waiting for the the popup to come up
            wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("/html/body/div[5]/div[2]/div[2]/table/tbody")));
            for (int j = 1; j <= driver.FindElements(By.XPath("/html/body/div[5]/div[2]/div[2]/table/tbody")).Count(); j++)
            {
                wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("/html/body/div[5]/div[2]/div[2]/table/tbody/tr["+j+"]")));
            }

            //tests the popup
            ProcessPopup();

            stopwatch.Stop();
            Console.WriteLine("This test took: " + stopwatch.ElapsedMilliseconds);

            driver.Quit();
        }
Exemplo n.º 27
0
 private void click_registration_button(ChromeDriver browser)
 {
     //  multiple submit buttons existed, we click the one that is visible
     var findElement =
         browser.FindElements(BySizzle.CssSelector("input[value=Register]")).First(e => e.Displayed);
     findElement.Click();
 }
Exemplo n.º 28
-1
         public static void GetData(string linkName, int marketId, int rowIndex, string className)
         {
              IWebDriver driver = new ChromeDriver();
            try
            {
                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl("http://www.mysteel.com/");
                var userName = driver.FindElement(By.Name("my_username"));
                userName.SendKeys("tx6215");
                var password = driver.FindElement(By.Name("my_password"));
                password.SendKeys("tx6215");
                userName.Submit();
                var steel = driver.FindElement(By.LinkText("型钢"));
                driver.Navigate().GoToUrl(steel.GetAttribute("href"));
                Thread.Sleep(2000);

                var mRows = driver.FindElement(By.ClassName("midCol")).FindElements(By.ClassName("mRow"));
                if(mRows != null && mRows.Count > 0)
                {
                    var mRow = mRows[rowIndex];
                    var moreLink = mRow.FindElement(By.ClassName(className)).FindElement(By.ClassName("more")).FindElement(By.TagName("a"));
                    driver.Navigate().GoToUrl(moreLink.GetAttribute("href"));
                    Thread.Sleep(2000);
                     var date = DateTime.Now.Day + "日";
                    
                    if(linkName == "上海" || linkName == "唐山")
                    {
                        var dataLinks = driver.FindElements(By.PartialLinkText(date + linkName));
                        var linkElements = dataLinks.Where(c => c.Text.Trim().Contains("价格行情")).ToList();
                        if(linkElements != null && linkElements.Count > 0)
                        {
                            GetDataL(driver, linkElements[i], marketId);
                            i++;
                            if (i < linkElements.Count)
                            {
                                GetData(linkName, marketId, rowIndex, className);
                            }
                        }
                        //if(linkElements != null && linkElements.Count > 0)
                        //{
                        //    foreach(var link in linkElements)
                        //    {
                        //        GetDataL(driver, link, marketId);
                        //    }
                        //}
                    }
                    else
                    {
                        var dataLink = driver.FindElement(By.LinkText(date + linkName));
                        if (dataLink != null)
                        {
                            GetDataL(driver, dataLink, marketId);
                        }
                    }
                }
                Thread.Sleep(2000);
                
            }
            finally
            {
                driver.Close();
                driver.Quit();
            }
        }
Exemplo n.º 29
-1
        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);
                }
            }
        }
Exemplo n.º 30
-1
        /// <summary>
        /// 
        /// </summary>
        /// <param name="chromeDriver"></param>
        /// <param name="containerXPath"></param>
        /// <param name="linkXPath"></param>
        /// <returns></returns>
        private List<IWebElement> getWebElementsByXPath(ChromeDriver chromeDriver, String containerXPath, String linkXPath)
        {
            try
            {
                // ищем все контейнеры, которые содержат containerXPath
                List<IWebElement> webConteiners = chromeDriver.FindElements(By.XPath(containerXPath)).ToList();
                if (webConteiners != null)
                {
                    List<IWebElement> returnElements = new List<IWebElement>();
                    foreach (IWebElement t in webConteiners) // получаем все контейнеры
                    {
                        // нужно пробежать по всем контейнерам и сложить все элементы linkXPath в этих контейнерах
                        List<IWebElement> webLinks = t.FindElements(By.XPath(linkXPath)).ToList();
                        foreach (IWebElement l in webLinks)
                        {
                            returnElements.Add(l);
                        }

                    }
                    return returnElements;
                }
            }
            catch (WebDriverException e)
            {
                System.Diagnostics.Trace.WriteLine(containerXPath + System.Environment.NewLine +
                                                   linkXPath + System.Environment.NewLine +
                                                   e.Message);
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(containerXPath + System.Environment.NewLine +
                                                   linkXPath + System.Environment.NewLine +
                                                   e.Message);
            }
            return new List<IWebElement>(); // возвращаем пустой массив
        }
Exemplo n.º 31
-10
        private static void CreateExcelFile(ChromeDriver driver)
        {
            var homeTeams = driver.FindElements(By.ClassName("team-home"));
            var awayTeams = driver.FindElements(By.ClassName("team-away"));
            var scores = driver.FindElements(By.ClassName("score"));

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("Scores");

            ws.Cell("A1").Value = "Home Team";
            ws.Cell("B1").Value = "Score";
            ws.Cell("C1").Value = "Away Team";

            for (int i = 0; i < homeTeams.Count; i++)
            {
                string homeTeam = homeTeams[i].Text;
                string score = scores[i].Text;
                string awayTeam = awayTeams[i].Text;

                ws.Cell("A" + (i + 2)).Value = homeTeam;
                ws.Cell("B" + (i + 2)).Value = score;
                ws.Cell("C" + (i + 2)).Value = awayTeam;
            }

            // Beautify
            ws.Range("A1:C1").Style.Font.Bold = true;
            ws.Columns().AdjustToContents();

            wb.SaveAs("../../../../FlashScore.xlsx");
        }