Пример #1
0
        public Result ForceBrowserClose(bool forceClose)
        {
            if (isLocal || forceClose)
            {
                try
                {
                    browser = new IE(Urls.Root);

                    browser.WaitForComplete();
                }
                catch (Exception e)
                {
                    Console.WriteLine("BaseFixture.ForceBrowserForDatabaseReset: " + e.ToString());

                    Thread.Sleep(500);

                    browser = new IE(Urls.Root);

                    browser.WaitForComplete();
                }

                CloseBrowser(forceClose);
            }

            return Result.CreatePass();
        }
 public void TestFixtureSetup()
 {
     rootURL = ConfigurationManager.AppSettings["RootURL"];
     // hide IE browser during tests
     Settings.Instance.MakeNewIeInstanceVisible = true;
     browser = new IE(rootURL + "Account/LogOn");
     browser.WaitForComplete();
 }
Пример #3
0
 public void Remote_server_does_nothing()
 {
     using (IWebServer server = WebServerFactory.CreateWebServer("Remote", "http://www.bing.com/", null, 0))
     using (Browser browser = new IE(server.RootUrl))
     {
         browser.WaitForComplete();
         Assert.Equal("Bing", browser.Title);
     }
 }
Пример #4
0
        public void UploadVideo(IE ie, string filePath)
        {
            ie.Link(Find.ById("uploadVideo")).Click();

            var fu = ie.FileUpload(Find.ById("ctl00_cphAdmin_txtUploadVideo"));
            fu.Set(filePath);

            ie.Button(Find.ById("ctl00_cphAdmin_btnUploadVideo")).Click();
            ie.WaitForComplete();
        }
Пример #5
0
 public void Sample_app_started_in_IISExpress()
 {
     using (IWebServer server = WebServerFactory.CreateWebServer())
     using (Browser browser = new IE(server.RootUrl))
     {
         browser.WaitForComplete();
         IndexPage page = browser.Page<IndexPage>();
         Assert.Contains("Please run the WatiN test", page.Message.Text);
     }
 }
Пример #6
0
        public void UploadImage(IE ie, string filePath)
        {
            ie.Link(Find.ById("uploadImage")).Click();

            var fu = ie.FileUpload(Find.ByClass("ImageUpload"));
            fu.Set(filePath);

            ie.Button(Find.ById("ctl00_cphAdmin_btnUploadImage")).Click();
            ie.WaitForComplete();
        }
Пример #7
0
        private static IE GetIEByIndex(ArrayList internetExplorers, int index, bool waitForComplete)
        {
            IE ie = (IE)internetExplorers[index];

            if (waitForComplete)
            {
                ie.WaitForComplete();
            }

            return(ie);
        }
Пример #8
0
 public ResultWindow(int timeLimit , string idProblem)
     : this()
 {
     this.timeLimit = timeLimit;
     this.idProblem = idProblem;
     Process process = new Process();
     process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
     process.StartInfo.CreateNoWindow = true;
     process.StartInfo.UseShellExecute = false;
     process.StartInfo.FileName = "cmd";
     process.StartInfo.Arguments =
         string.Format("/C \"\"{0}\" < \"{1}\" > \"{2}\"\"",
         Properties.Settings.Default.FileExec,
         Properties.Settings.Default.FileInput,
         Properties.Settings.Default.FileOutput);
     process.Start();
     if (!process.WaitForExit(timeLimit * 1000))
         process.Kill();
     if (process.ExitCode != 0)
     {
         runtime.Visibility = Visibility.Visible;
         return;
     }
     timeExec.Content = process.TotalProcessorTime.Milliseconds / 1000f + "s";
     try
     {
         textInput = File.ReadAllText(Properties.Settings.Default.FileInput);
         textOutput = File.ReadAllText(Properties.Settings.Default.FileOutput);
         textOutput = textOutput.Replace("\r\n", "\n");
         //Settings.MakeNewIeInstanceVisible = false;
         WatiN.Core.Settings.Instance.AutoMoveMousePointerToTopLeft = false;
         browser = new IE(prefix + idProblem);
         TextField inputField = browser.TextField(Find.ById("edit-input-data"));
         WatiN.Core.Button buttonSubmit = browser.Button(Find.ById("edit-output"));
         inputField.Value = textInput;
         buttonSubmit.Click();
         browser.WaitForComplete();
         string result = browser.Html;
         int begin = result.IndexOf("<pre>") + 5;
         textCorrect = result.Substring(begin, result.IndexOf("</pre>") - begin);
         File.WriteAllText(Properties.Settings.Default.FileCorrect, textCorrect);
         if (textOutput != textCorrect)
             incorrect.Visibility = Visibility.Visible;
         else
             accepted.Visibility = Visibility.Visible;
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     browser.ForceClose();
 }
Пример #9
0
 public void TestClickNextBlog()
 {
     using (var browser = new IE("http://localhost:8888/Blog/My-New-iMac"))
     {
         var funnyDialog = new AlertDialogHandler();
         using (new UseDialogOnce(browser.DialogWatcher, funnyDialog))
         {
             browser.Link("MainContent_linkNextBlog").ClickNoWait();
             funnyDialog.WaitUntilExists();
             funnyDialog.OKButton.Click();
             Assert.IsTrue(funnyDialog.Message.Contains("I've told you I am writing:)"));
         }
         browser.WaitForComplete(3);
     }
 }
        public void SuccessfulAdministrationLogin()
        {
            var browserUrl = string.Empty;
            using (var browser = new IE("http://localhost:1200/"))
            {
                browser.Link(Find.ByText("Admin")).Click();
                browser.TextField(Find.ById("UserName")).TypeText("administrator");
                browser.TextField(Find.ById("Password")).TypeText("password123!");

                browser.Element(Find.ByValue("Log On")).Click();
                browser.WaitForComplete(2);

                browserUrl = browser.Url;
            }

            Assert.That(browserUrl.Contains("/StoreManager"), string.Format("Browser Url is incorrect - it is actually {0}", browserUrl));
        }
Пример #11
0
        public void TestWebUIButtonValidation()
        {
            var input = 0;

            string[] Headers = { "All Numbers:",
                                 "All Odd Numbers:",
                                 "All Even Numbers:",
                                 "All Extended FizzBuzzs:",
                                 "All Fibonacci Numbers:" };

            using (var browser = new WatiN.Core.IE(testUrl))
            {
                browser.TextField(Find.ByName("txtNumber")).TypeText(input.ToString());
                browser.Button(Find.ByName("btnGenerate")).Click();
                browser.WaitForComplete();

                Assert.IsTrue(string.IsNullOrWhiteSpace(browser.Divs[0].Text));
            }
        }
Пример #12
0
        public bool DeletePostByTitle(string title, IE ie)
        {
            ie.GoTo(Url);
            ie.WaitForComplete();

            var tblPosts = ie.Table("Posts");

            if (tblPosts != null)
            {
                foreach (var row in tblPosts.TableRows)
                {
                    if (!string.IsNullOrEmpty(row.Id) && row.InnerHtml.Contains(title))
                    {
                        ie.Link("a-" + row.Id).Click();
                        return true;
                    }
                }
            }
            return false;
        }
Пример #13
0
        void StressThread()
        {
            //Settings.WaitForCompleteTimeOut = 3600;
            //Settings.WaitUntilExistsTimeOut = 3600;
            
            using (IE ie = new IE("http://*****:*****@"C:\Users\Chris\Downloads\Firefox Setup 7.0.exe");

                //_waitEvent.WaitOne();
                ie.Link(Find.ById("uploadButton")).Click();

                while (!ie.ContainsText("Upload Result"))
                {
                    Thread.Sleep(1000);
                    //ie.WaitForComplete();
                }

                Assert.True(ie.ContainsText("Complete"));

                ie.Link(Find.ById("newUploadButton")).Click();
                ie.WaitForComplete();

                SetFileUpload(ie, "slickUpload_selector_html_file0", @"C:\Users\Chris\Downloads\SlickUpload-6.1-S3MetadataFix.zip");
                SetFileUpload(ie, "slickUpload_selector_html_file1", @"C:\Users\Chris\Downloads\MSBuild Extension Pack April 2011 (All Files) (1).zip");
                ie.Link(Find.ById("uploadButton")).Click();

                while (!ie.ContainsText("Upload Result"))
                {
                    Thread.Sleep(1000);
                    //ie.WaitForComplete();
                }

                Assert.True(ie.ContainsText("Complete"));

                //Thread.Sleep(10000);
            }
        }
        public void Check_That_When_Logged_In_As_Admin_Then_Add_Product_Works()
        {
            var result = false;
            using (IE netWindow = new IE("http://localhost:49573/default.aspx"))
            {
                LoginAsAdmin(netWindow);

                netWindow.Link(Find.ById("ctl00_ucHeader_lnkAdminPage")).Click();
                #region hidden new way
                netWindow.Link(Find.ById(new Regex("AdminPage$")));
                #endregion

                netWindow.WaitForComplete();

                netWindow.Button(Find.ById("ctl00_ucHeader_lnkProductAdmin")).Click();
                netWindow.WaitForComplete();

                netWindow.Button(Find.ById("ctl00_ContentPlaceHolder1_RadDock1_C_btnAddProduct")).Click();
                netWindow.WaitForComplete();

                netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_txtProductName")).TypeText(String.Format("Paul Test Product {0}", DateTime.Now.Ticks.ToString()));
                netWindow.SelectList(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ddlProductManufacturer")).SelectByValue("3");
                netWindow.SelectList(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ddlCategoryList")).SelectByValue("2");
                netWindow.WaitForComplete(100);
                netWindow.SelectList(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ddlSubCategoryList")).SelectByValue("2");
                netWindow.WaitForComplete();
                netWindow.Link(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_btnAddCombo")).Click();
                netWindow.WaitForComplete();
                netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_txtProductPrice")).TypeText("19.99");
                netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_txtProductModel")).TypeText("Paul Test Model 1");
                netWindow.Link(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_btnSave")).Click();

                netWindow.WaitForComplete();

                Span resultMessage = netWindow.Span(Find.ById("ctl00_ContentPlaceHolder1_ucProduct_ucMessage_lblMessage"));
                if (resultMessage.Text == "New Product created successfuly")
                {
                    result = true;
                }
            }
            Assert.IsTrue(result);
        }
Пример #15
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                IE ie = new IE();

                ie.GoTo("www.terra.com.br");

                ie.WaitForComplete();

                ie.TextField("autocomplete").Value = "esporte";
                ie.TextField("autocomplete").Focus();

                SendKeys.SendWait("{ENTER}");
                //ie.TextField("autocomplete").KeyPress((char)Keys.Enter);

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
Пример #16
0
        public static void GetNewAccount(out string Account, out string Password)
        {
            // Windows
            WatiN.Core.IE window = new WatiN.Core.IE("http://www.forexmicrolot.com/open-free-micro-uk.jsp");

            // Frames

            // Model
            var        frame       = ((WatiN.Core.Document)(window)).Frames[0];
            TextField  txt_FNAME   = frame.TextField(Find.ByName("FNAME"));
            TextField  txt_LNAME   = frame.TextField(Find.ByName("LNAME"));
            TableCell  td_         = frame.TableCell(Find.ByText(""));
            SelectList sel_COUNTRY = frame.SelectList(Find.ByName("COUNTRY"));
            TextField  txt_EMAIL   = frame.TextField(Find.ByName("EMAIL"));
            Image      img_submit  = frame.Image(Find.ByName("submit"));

            // Code
            txt_FNAME.Click();
            txt_FNAME.TypeText("a");
            txt_LNAME.Click();
            txt_LNAME.TypeText("a");
            td_.Click();
            sel_COUNTRY.SelectByValue("Afghanistan");
            txt_EMAIL.Click();
            txt_EMAIL.TypeText("*****@*****.**");
            td_.Click();
            img_submit.Click();
            window.WaitForComplete();
            frame = ((WatiN.Core.Document)(window)).Frames[0];
            var TD = frame.TableCell(td => td.Text == "User ID");

            Account  = TD.ContainingTableRow.OwnTableCells[2].Text;
            TD       = frame.TableCell(td => td.Text == "Password");
            Password = TD.ContainingTableRow.OwnTableCells[2].Text;
            window.Dispose();
        }
Пример #17
0
        public void PopulateBrandMobilePhones(IEnumerable<int> brandIdList)
        {
            Settings.AttachToBrowserTimeOut = 240;
            Settings.WaitUntilExistsTimeOut = 240;
            Settings.WaitForCompleteTimeOut = 240;
            using (var dbContext = new MobilesDbContext())
            {
                try
                {
                    List<BrandPage> brandPages =
                        dbContext.BrandPages.Include("Brand").Where(p => brandIdList.Contains(p.Brand.Id) && p.IsRead == false).ToList();
                    foreach (BrandPage brandPage in brandPages)
                    {
                        string url = brandPage.Url;
                        try
                        {
                            using (var browser = new IE(url, true))
                            {
                                browser.ShowWindow(NativeMethods.WindowShowStyle.Hide);
                                browser.WaitForComplete();

                                IEnumerable<Div> productsDivs =
                                    browser.Divs.Where(d => d.ClassName != null && d.ClassName.Contains("makers"));

                                var listOfProducts = new List<OnlineShopModel.Product>();
                                foreach (Div productDiv in productsDivs)
                                {
                                    List productsList = productDiv.Lists.First();

                                    if (productsList != null && productsList.Exists)
                                    {
                                        foreach (ListItem productListItem in productsList.ListItems)
                                        {
                                            Link productLink = productListItem.Links.First();
                                            Element productName =
                                                productLink.Children().Where(c => c.TagName.ToUpper() == "STRONG").First();
                                            Image productImage = productLink.Images.First();
                                            listOfProducts.Add(new OnlineShopModel.Product
                                            {
                                                ProductName = productName.Text,
                                                Url = productLink.Url,
                                                ImageUrl = productImage.Src,
                                                Description = productImage.Title
                                            });
                                        }
                                    }
                                }

                                Database.SetInitializer(new CreateDatabaseIfNotExists<MobilesDbContext>());

                                List<Product> dbProductsList = dbContext.Products.ToList();

                                foreach (OnlineShopModel.Product product in listOfProducts)
                                {
                                    Product filterProduct = dbProductsList.Where(p => p.Url == product.Url).FirstOrDefault();
                                    if (filterProduct == null)
                                    {
                                        Product dbProduct = GetDbProduct(product);
                                        dbProduct.Brand = brandPage.Brand;
                                        dbContext.Products.Add(dbProduct);
                                    }
                                }

                                brandPage.IsRead = true;

                                dbContext.SaveChanges();
                            }
                        }
                        catch (Exception)
                        {

                        }

                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                    //throw ex;
                }
            }
        }
Пример #18
0
 static void Main(string[] args)
 {
     //Делаем компилятор счастливым
     string username = "";
     System.Console.WriteLine("OZWar Bot v1.0");
     System.Console.WriteLine("Инициализация IE...");
     //Инициализация ватина
     WatiN.Core.IE ieb = new IE("http://ozwar.ru/forum/index.php?app=core&module=global&section=login");
     ieb.Visible = false;
     int ii = 0;
     while (ii == 0)
     {
         System.Console.WriteLine("Авторизация...");
         ieb.WaitForComplete();
         //Вводим данные
         System.Console.WriteLine("Введите имя пользователя:");
         username = System.Console.ReadLine();
         System.Console.WriteLine("Введите пароль:");
         string password = System.Console.ReadLine();
         ieb.TextField(WatiN.Core.Find.ByName("ips_username")).TypeText(username);
         ieb.TextField(WatiN.Core.Find.ByName("ips_password")).TypeText(password);
         ieb.Button(WatiN.Core.Find.ByClass("input_submit")).Click();
         ieb.WaitForComplete();
         if (ieb.Link(WatiN.Core.Find.ByTitle(username)).Exists)
         {
             ii = 1;
         }
     }
     //Смотрим баланс
     ieb.GoTo(ieb.Link(WatiN.Core.Find.ByTitle(username)).Url);
     ieb.WaitForComplete();
     System.Console.WriteLine("Баланс: " + ieb.Span(WatiN.Core.Find.ByClass("fc")).Text.ToString());
     System.Console.WriteLine("Грузим ссылки...");
     //Грузим ссылки
     var ar1 = new List<string>();
     System.IO.StreamReader file = new System.IO.StreamReader(@"c:\list.txt");
     string line;
     while ((line = file.ReadLine()) != null)
     {
         ar1.Add(line);
     }
     //Грузим фразы
     System.Console.WriteLine("Грузим фразы...");
     var ar2 = new List<string>();
     System.IO.StreamReader file2 = new System.IO.StreamReader(@"c:\phrases.txt");
     string line2 = "";
     while ((line2 = file2.ReadLine()) != null)
     {
         ar2.Add(line2);
     }
     int co = 0;
     while (co < ar1.Count)
     {
         ieb.GoTo(ar1[co]);
         ieb.WaitForComplete();
         if (!ieb.Link(WatiN.Core.Find.ByTitle("Изменить")).Exists)
         {
             System.Console.WriteLine("Текущая ссылка: " + ar1[co]);
             int rnd = RandomInt(0, ar2.Count);
             System.Console.WriteLine("Пишем");
             ieb.TextField(WatiN.Core.Find.ByName("Post")).TypeTextQuickly(ar2[rnd] + "[color=#222222]Эта информация тут только для дебага, цыц, вы этого не видели. Не, ну серьёзно. Ну, а раз видели, значит её сейчас, к сожалению, сейчас не станет. Это сообщение отправлено ботом OreNew, пожалуйста, не читайте его.[/color]");
             ieb.Form(WatiN.Core.Find.ById("ips_fastReplyForm")).Submit();
             ieb.WaitForComplete();
             ieb.GoTo(ieb.Link(WatiN.Core.Find.ByTitle("Изменить")).Url);
             ieb.WaitForComplete();
             ieb.TextField(WatiN.Core.Find.ByName("Post")).TypeText(ar2[rnd]);
             ieb.Form(WatiN.Core.Find.ById("postingform")).Submit();
             System.Console.WriteLine("Выполнено");
             ieb.GoTo("http://ozwar.ru/forum/index.php?/user/609-benderfromfuture/");
             ieb.WaitForComplete();
             System.Console.WriteLine("Баланс: " + ieb.Span(WatiN.Core.Find.ByClass("fc")).Text.ToString());
             co++;
         }
         else
         {
             System.Console.WriteLine("Найдены следы нас!");
             co++;
         }
         System.Console.WriteLine("Ссылки кончились, бот завершил свою работу");
         ieb.Link(WatiN.Core.Find.ByTitle("Выход")).Click();
         System.Console.WriteLine("Выход из профиля...");
         System.Console.ReadLine();
     }
 }
Пример #19
0
 public virtual void SetUp()
 {
     browser = new IE(ConfigureWebResources.GetHarnessUrl(harnessMode));
     browser.WaitForComplete();
 }
Пример #20
0
        public void WebApplicationScraping()
        {
            try
            {
                // Reads the path of the web application
                string webSitePath = Convert.ToString(ConfigurationManager.AppSettings["WebApplicationPath"]);
                string filePhysicalPath = Convert.ToString(ConfigurationManager.AppSettings["ScraperEnginePhysicalLocation"]);

                StreamWriter file = new StreamWriter(filePhysicalPath + "Output.txt");

                if (webSitePath != null && webSitePath != string.Empty)
                {
                    // Create an instance of IE browser
                    IE ieInstance = new IE(webSitePath);

                    // This will opens IE browser in maximized mode
                    ieInstance.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);

                    // Watin window will not visible to the end user when web scraping is done
                    //ieInstance.Visible = false;

                    // This will wait for the browser to complete loading of the page
                    ieInstance.WaitForComplete();

                    // This will store page source in categoryPageSource variable
                    string categoryPageSource = ieInstance.Html;

                    // Regular expression pattern to fetch list of categories categories

                    Regex categoryMatches = new Regex(_categoryRegEx, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant);

                    // Fetches all the categories based upon category regex from category listing page
                    MatchCollection categoryMatchCollection = categoryMatches.Matches(categoryPageSource);

                    // Navigate to each categories and fetch page URL and navigate to the item listing page for each categories
                    foreach (Match categoryMatch in categoryMatchCollection)
                    {
                        GroupCollection categoryGroup = categoryMatch.Groups;

                        // URL of the item listing page
                        string itemListingURL = Convert.ToString(categoryGroup["href"].Value);

                        // Partial web path where demonstration web site is deployed.
                        // Note: This path needs to be modified in App.Config file accordingly.
                        string webSiteHostedLocation = webSitePath.Remove(webSitePath.LastIndexOf("/"));

                        // Creates path of the category listing page.
                        string itemListingpath = webSiteHostedLocation + "/" + itemListingURL;

                        // Navigate to the item listing page
                        ieInstance.GoTo(itemListingpath);

                        ieInstance.WaitForComplete();

                        // HTML source of given generated web page
                        string itemListingPageSource = ieInstance.Html;

                        // Match for the paging Event
                        Regex pagingMatches = new Regex(_pagingRegEx, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant | RegexOptions.Multiline);

                        // Find Matches.
                        MatchCollection pagingMatchCollection = pagingMatches.Matches(itemListingPageSource);

                        foreach (Match pageMatch in pagingMatchCollection)
                        {
                            GroupCollection pagingGroup = pageMatch.Groups;

                            if (pagingGroup[_pageNumber].Value != "1")
                            {
                                // Fetches the page number of the current page.
                                string linkText = Convert.ToString(pagingGroup[_pageNumber].Value);

                                // Performs click event on the given link. For e.g if linkText contains "2" as a value then 
                                //Watin will perform click event on this second link.
                                ieInstance.Link(Find.ByText(linkText)).Click();

                                // Wait for the operation to complete
                                ieInstance.WaitForComplete();

                                // Store the result of the page in itemListingPageSource variable
                                itemListingPageSource = ieInstance.Html;
                            }

                            Regex itemMatches = new Regex(_itemRegEx, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.CultureInvariant);

                            // Fetches all the items based upon item regex from the item listing page
                            MatchCollection itemMatchCollection = itemMatches.Matches(itemListingPageSource);

                            // Navigate to each item and fetch ProductID, ProductName and ProductPrice and store the result in text file
                            foreach (Match itemMatch in itemMatchCollection)
                            {
                                GroupCollection itemGroups = itemMatch.Groups;

                                // Fetch productId from the given item group
                                string productID = Convert.ToString(itemGroups[_productID].Value);

                                // Fetch productName from the given item Group
                                string productName = Convert.ToString(itemGroups[_productName].Value);

                                // Fetch product price from the given product price
                                string productPrice = Convert.ToString(itemGroups[_productPrice].Value);

                                file.WriteLine("ProductID: " + productID);

                                file.WriteLine("Product Name: " + productName);

                                file.WriteLine("Product Price: " + productPrice);

                                file.WriteLine("-----------------------------------------------------------------------------------------------");

                                file.WriteLine("\n");
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Mention category listing website application path");
                }

                file.Close();
            }
            catch (Exception ex)
            {

            }
            finally
            {

            }
        }
Пример #21
0
        private void Go_Click(object sender, EventArgs e)
        {
            _IsProduct = false;
            _percent.Visible = false;
            _Bar1.Value = 0;
            _lblerror.Visible = false;
            _Pages = 0;
            _TotalRecords = 0;
            gridindex = 0;
            _IsCategory = true;
            _Stop = false;
            time = 0;

            _Worker1 = new IE();
            _Worker2 = new IE();

            #region Factory.ca
            _ScrapeUrl = "http://www.factorydirect.ca/SearchResults.aspx";
            try
            {

                _lblerror.Visible = true;
                _lblerror.Text = "We are going to read category Link for factorydirect.ca Website";
                int counterReload = 0;
                bool isError = false;

                _Worker1.GoTo(_ScrapeUrl);
                _Worker1.WaitForComplete();
                System.Threading.Thread.Sleep(10000);
                _Work1doc.LoadHtml(_Worker1.Html);

                HtmlNodeCollection _CollectionCatLink = _Work1doc.DocumentNode.SelectNodes("//b[@class=\"nxt-result-total\"]");
                if (_CollectionCatLink != null)
                {
                    try
                    {
                        _TotalRecords = Convert.ToInt32(_CollectionCatLink[0].InnerText.Trim());
                        if ((_TotalRecords % 36) == 0)
                        {
                            _Pages = Convert.ToInt32(_TotalRecords / 36);
                        }
                        else
                        {
                            _Pages = Convert.ToInt32(_TotalRecords / 36) + 1;
                        }
                    }
                    catch
                    { }

                    while (_Work.IsBusy || _Work1.IsBusy)
                    {
                        Application.DoEvents();

                    }
                    if (_TotalRecords > 0)
                    {
                        gridindex = 0;
                        _Bar1.Value = 0;
                        _percent.Visible = false;
                        _lblerror.Visible = true;
                        _lblerror.Text = "We are going to read products from search page.";
                        _Stop = false;
                        time = 0;
                        _IsCategory = true;
                        tim(3);
                        totalrecord.Visible = true;

                        for (int Page = 1; Page <= _Pages; Page++)
                        {
                            CategoryUrl.Add("http://www.factorydirect.ca/SearchResults.aspx#/?search_return=all&res_per_page=36&page=" + Page);
                        }
                        totalrecord.Text = "Total No Pages :" + CategoryUrl.Count.ToString();

                        foreach (string url in CategoryUrl)
                        {
                            while (_Work.IsBusy && _Work1.IsBusy)
                            {
                                Application.DoEvents();
                            }

                            if (!_Work.IsBusy)
                            {
                                Url1 = url;
                                _Work.RunWorkerAsync();
                            }
                            else
                            {
                                Url2 = url;
                                _Work1.RunWorkerAsync();
                            }

                        }
                        while (_Work.IsBusy || _Work1.IsBusy)
                        {
                            Application.DoEvents();

                        }
                        _lblerror.Visible = true;
                        _lblerror.Text = "We are going to read product info.";
                        _IsCategory = false;
                        _IsProduct = true;
                        gridindex = 0;
                        totalrecord.Text = "Total No Products :" + Producturl.Count.ToString();
                        foreach (var url in Producturl)
                        {
                            while (_Work.IsBusy && _Work1.IsBusy)
                            {
                                Application.DoEvents();
                            }

                            if (!_Work.IsBusy)
                            {
                                Url1 = url.Key;
                                _Work.RunWorkerAsync();
                            }
                            else
                            {
                                Url2 = url.Key;
                                _Work1.RunWorkerAsync();
                            }
                        }
                        while (_Work.IsBusy || _Work1.IsBusy)
                        {
                            Application.DoEvents();

                        }

                        #region InsertScrappedProductInDatabase

                        if (Products.Count() > 0)
                        {
                            _Prd.ProductDatabaseIntegration(Products, "factorydirect.ca", 1);

                        }
                        else
                        {
                            BusinessLayer.DB _Db = new BusinessLayer.DB();
                            _Db.ExecuteCommand("update Schduler set LastProcessedStatus=0 where StoreName='factorydirect.ca'");
                            _Prd.ProductDatabaseIntegration(Products, "factorydirect.ca", 1);
                            _Mail.SendMail("OOPS there is no any product scrapped by app for factorydirect.ca Website." + DateTime.Now.ToString(), "Urgent issue in Scrapper.", false, false, 1);
                        }
                        #endregion InsertScrappedProductInDatabase
                    }
                    else
                    {
                        BusinessLayer.DB _Db = new BusinessLayer.DB();
                        _Prd.ProductDatabaseIntegration(Products, "factorydirect.ca", 1);
                        _Db.ExecuteCommand("update Schduler set LastProcessedStatus=0 where StoreName='factorydirect.ca'");
                        _lblerror.Text = "Oops there is change in html code  on client side. You need to contact with developer in order to check this issue for factorydirect.ca Website";
                        /****************Email****************/
                        _Mail.SendMail("Oops there is change in html code  on client side. You need to contact with developer in order to check this issue for factorydirect.ca Website as soon as possible because noscrapping of given store is stopped working." + DateTime.Now.ToString(), "Urgent issue in Scrapper.", false, false, 1);
                        /*******************End********/
                    }

                }

                else
                {
                    BusinessLayer.DB _Db = new BusinessLayer.DB();
                    _Prd.ProductDatabaseIntegration(Products, "factorydirect.ca", 1);
                    _Db.ExecuteCommand("update Schduler set LastProcessedStatus=0 where StoreName='factorydirect.ca'");
                    _lblerror.Text = "Oops there is change in html code  on client side. You need to contact with developer in order to check this issue for factorydirect.ca Website";
                    /****************Email****************/
                    _Mail.SendMail("Oops there is change in html code  on client side. You need to contact with developer in order to check this issue for factorydirect.ca Website as soon as possible because noscrapping of given store is stopped working." + DateTime.Now.ToString(), "Urgent issue in Scrapper.", false, false, 1);
                    /*******************End********/
                }
            }
            catch
            {
                BusinessLayer.DB _Db = new BusinessLayer.DB();
                _Db.ExecuteCommand("update Schduler set LastProcessedStatus=0 where StoreName='factorydirect.ca'");
                _lblerror.Visible = true;
                _Mail.SendMail("Oops Some issue Occured in scrapping data factorydirect.ca Website" + DateTime.Now.ToString(), "Urgent issue in Scrapper.", false, false, 1);

            }
            while (_Work.IsBusy || _Work1.IsBusy)
            {
                Application.DoEvents();

            }
            # endregion Factory.CA
            writer.Close();

            try { _Worker1.Close(); _Worker2.Close(); }
            catch
            {

            }
            this.Close();
        }
Пример #22
0
        private static void GetPatentsInYear(int year)
        {
            using (var browser = new IE(resource))
            {
                // go to the search form
                browser.Button(Find.ByName("menu")).ClickNoWait();

                // fill out search form and submit
                browser.CheckBox(Find.ByName("brugsmodel")).Click();
                browser.SelectList(Find.ByName("datotype")).Select("Patent/reg. dato");
                browser.TextField(Find.ByName("dato")).Value = string.Format("{0}*", year);
                browser.Button(Find.By("type", "submit")).ClickNoWait();
                browser.WaitForComplete();

                // go to first patent found in search result and save it
                browser.Buttons.Filter(Find.ByValue("Vis")).First().Click();
                GetPatentFromPage(browser, year);

                // hit the 'next' button until it's no longer there
                while (GetNextPatentButton(browser).Exists)
                {
                    GetNextPatentButton(browser).Click();
                    GetPatentFromPage(browser, year);
                }
            }
        }
Пример #23
0
        public void FetchLeetCode()
        {
            using (var browser = new IE("https://leetcode.com"))
            {

                using (StreamReader sr = new StreamReader(Directory + @"template\solution.html"))
                {
                    string solutionTemplate = sr.ReadToEnd();

                    using (StreamReader questionReader = new StreamReader(Directory + @"template\question.html"))
                    {
                        string questionTemplate = questionReader.ReadToEnd();

                        var toHtml = new IE("http://hilite.me/");

                        browser.Link(Find.ByClass("btn btn-default")).Click();
                        browser.TextField(Find.ById("id_login")).SetAttributeValue("value", "*****@*****.**"); //TypeText("*****@*****.**");
                        browser.TextField(Find.ById("id_password")).SetAttributeValue("value", "Test123"); //.TypeText("Test123");
                        browser.Button(Find.ByText("Sign In")).Click();

                        for (int i = 115; i < 300; ++i)
                        {
                            var table = browser.Table(Find.ById("problemList"));
                            var body = table.TableBodies[0];
                            foreach (var row in body.OwnTableRows)
                            {
                                if (row.Elements != null && row.Elements.Count > 0 && "ac" == row.Elements[1].ClassName)
                                {
                                    var cell2 = row.Elements[2] as TableCell;
                                    string questionIndex = cell2.Text;

                                    if (Int32.Parse(questionIndex) == i)
                                    {
                                        var cell = row.Elements[3] as TableCell;
                                        string questionName = cell.Text;
                                        cell.Links[0].Click();

                                        var questionDiv = browser.Div(Find.ByClass("question-content"));

                                        string questionContent = "";

                                        for (int j = 0; j < questionDiv.Paras.Count; ++j)
                                        {
                                            if (!string.IsNullOrEmpty(questionDiv.Paras[j].Text) &&
                                                questionDiv.Paras[j].Text.StartsWith("<b>Notes:</b>"))
                                            {
                                                break;
                                            }
                                            questionContent += "<p>" + questionDiv.Paras[j].Text + "</p>";
                                        }

                                        //browser.Links.SelectMany(l => l.Text == "My Submissions");
                                        browser.Links.Filter(l => l.Text == "My Submissions").Where(l => l.Url != "https://leetcode.com/submissions/").First().Click();
                                        //browser.Link(Find.ByText("My Submissions") ).  .Click();
                                        browser.WaitForComplete();

                                        var tableResult = browser.Table(Find.ById("result_testcases"));
                                        var resultBody = tableResult.TableBodies[0];

                                        string solutionCode = "";

                                        foreach (var resultRow in resultBody.OwnTableRows)
                                        {
                                            if (resultRow.Elements[3].Text.Contains("Accepted"))
                                            {
                                                var acceptedCell = resultRow.Elements[3] as TableCell;
                                                acceptedCell.Links[0].Click();

                                                var div = browser.Div(Find.ByClass("ace_content"));
                                                solutionCode = div.Text;
                                                solutionCode = solutionCode.Replace("\r\n\r\n", "\r\n");
                                                break;
                                            }
                                        }

                                        toHtml.TextField(Find.ById("divstyles")).SetAttributeValue("value", "padding:.1em .3em;");

                                        toHtml.TextField(Find.ByName("code")).SetAttributeValue("value", solutionCode);

                                        toHtml.SelectList(Find.ByName("lexer")).SelectByValue("cpp");

                                        toHtml.Button(Find.ByValue("Highlight!")).Click();

                                        toHtml.WaitForComplete(3);

                                        string questionhtml = questionTemplate.Replace("<%QuestionName%>", questionName).Replace("<%QuestionContent%>", questionContent);
                                        string solutonhtml = solutionTemplate.Replace("<%QuestionName%>", questionName).Replace("<%SolutionTemplate%>", toHtml.TextField(Find.ById("html")).Text);
                                        solutonhtml = solutonhtml.Replace("margin: 0; line-height: 125%", "margin: 0; line-height: 125%; white-space: pre-wrap;");

                                        string solutionFilename = Directory + "output\\" + questionIndex + ".solution.html";
                                        string questionFileName = Directory + "output\\" + questionIndex + ".question.html";

                                        System.IO.File.WriteAllText(solutionFilename, solutonhtml);
                                        System.IO.File.WriteAllText(questionFileName, questionhtml);

                                        browser.GoTo("https://leetcode.com/problemset/algorithms/");
                                    }
                                }
                            }

                        }

                    }
                }
            }
        }
Пример #24
0
 public static string Goto(String text, IE ie)
 {
     int i = 0;
     while (i < Loop)
     {
         i++;
         try
         {
             ie.GoTo(text);
             ie.WaitForComplete();
             //ie.WaitUntilContainsText("message");
             return string.Empty;
         }
         catch (Exception ex)
         {
             if (i == Loop)
             {
                 return ex.Message;
             }
             ie.Close();
             Thread.Sleep(60000);
             ie.Reopen();
         }
     }
     return string.Empty;
 }
Пример #25
0
		private static IE findIE(BaseConstraint findBy, int timeout, bool waitForComplete)
		{
			SHDocVw.InternetExplorer internetExplorer = findInternetExplorer(findBy, timeout);

			if (internetExplorer != null)
			{
				IE ie = new IE(internetExplorer);
                if (waitForComplete)
                {
			        ie.WaitForComplete();
			    }

				return ie;
			}

			throw new IENotFoundException(findBy.ConstraintToString(), timeout);
		}
        public void Check_That_When_Logged_In_As_Admin_Then_Admin_Link_Goes_To_Admin_HomePage()
        {
            var url = string.Empty;
            //Act
            using (IE netWindow = new IE("http://localhost:49573/default.aspx"))
            {
                LoginAsAdmin(netWindow);

                netWindow.Link(Find.ById("ctl00_ucHeader_lnkAdminPage")).Click();
                netWindow.WaitForComplete();

                url = netWindow.Url;
            }
            Assert.AreEqual("http://localhost:49573//administration/default.aspx", url);
        }
        private static void LoginAsAdmin(IE netWindow)
        {
            //go to login page
            netWindow.GoTo("http://*****:*****@hotmail.com");
            netWindow.TextField(Find.ById("ctl00_ContentPlaceHolder1_ucLogin_txtPassword")).TypeText("");
            netWindow.Button(Find.ById("ctl00_ContentPlaceHolder1_ucLogin_btnLogin")).Click();
            netWindow.WaitForComplete(100);
        }
Пример #28
0
        public void PopulateBrandPages(IEnumerable<int> brandIdList)
        {
            Settings.AttachToBrowserTimeOut = 240;
            Settings.WaitUntilExistsTimeOut = 240;
            Settings.WaitForCompleteTimeOut = 240;
            using (var dbContext = new MobilesDbContext())
            {
                try
                {
                    List<string> brandPagesList = dbContext.BrandPages.Select(b => b.Url).Distinct().ToList();
                   List<DataModels.Brand> brands = dbContext.Brands.Where(b => brandIdList.Contains(b.Id)).ToList();
                  //  List<DataModels.Brand> brands = dbContext.Brands.ToList();
                    foreach (DataModels.Brand brand in brands)
                    {
                       // KillIeProcesses();
                        if (brandPagesList.Contains(brand.Url).Equals(false))
                        {
                            brand.BrandPages.Add(new BrandPage
                                                     {
                                                         Url = brand.Url,
                                                         IsInitialPage = true
                                                     });
                        }

                        string url = brand.Url;
                        using (var browser = new IE(url,true))
                        {
                            browser.ShowWindow(NativeMethods.WindowShowStyle.ForceMinimized);
                            browser.WaitForComplete();

                            Div mainDiv = browser.Div(Find.ById("main"));
                            if (mainDiv.Exists)
                            {
                                Div navigationDiv =
                                    mainDiv.Divs.Where(d => d.ClassName != null && d.ClassName.Contains("nav-pages")).
                                        FirstOrDefault();
                                if (navigationDiv != null && navigationDiv.Exists)
                                {
                                    List<string> pageLinks =
                                        navigationDiv.Links.Select(l=>l.Url).Distinct().ToList();

                                    foreach (var pageLink in pageLinks)
                                    {
                                        if (brandPagesList.Contains(pageLink).Equals(false))
                                        {
                                            brand.BrandPages.Add(new BrandPage
                                            {
                                                Url = pageLink
                                            });
                                        }
                                    }
                                }
                            }
                        }

                        dbContext.SaveChanges();
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadLine();
                    //throw ex;
                }
            }
        }
Пример #29
0
        public void Process()
        {
            _IsProduct = false;
            _Name.Clear();
            CategoryUrl.Clear();
            _ProductUrlthread1.Clear();
            _ProductUrlthread1.Clear();
            Url.Clear();
            _percent.Visible = false;
            _Bar1.Value = 0;
            _Url.Clear();
            _lblerror.Visible = false;
            _Pages = 0;
            _TotalRecords = 0;
            gridindex = 0;
            _Stop = false;
            time = 0;

            #region tigerdirect.ca
            _IStigerdirect = true;
            _ScrapeUrl = "http://tigerdirect.ca/";
            try
            {
                _Worker1 = new IE();
                _Worker2 = new IE();
                _lblerror.Visible = true;
                _lblerror.Text = "We are going to read  category url of " + chkstorelist.Items[0].ToString() + " Website";
                _Worker1.GoTo(_ScrapeUrl);
                _Worker1.WaitForComplete();
                System.Threading.Thread.Sleep(10);
                _Work1doc.LoadHtml(_Worker1.Html);
                HtmlNodeCollection _Collection = _Work1doc.DocumentNode.SelectNodes("//ul[@class=\"mastNav-subCats\"]/li/a");

                if (_Collection != null)
                {
                    foreach (HtmlNode node in _Collection)
                    {
                        foreach (HtmlAttribute att in node.Attributes)
                        {
                            if (att.Name == "href")
                                try
                                {
                                    CategoryUrl.Add("http://www.tigerdirect.ca" + (att.Value.Contains("?") ? att.Value + "&recs=30" : att.Value + "?recs=30"), "TGRDRCT" + node.InnerText.Trim());
                                }
                                catch
                                { }
                        }
                    }
                }
                try
                {
                    CategoryUrl.Add("http://www.tigerdirect.ca/applications/Category/guidedSearch.asp?CatId=21&sel=Detail%3B358_1565_8718_8718&cm_re=Printers-_-Spot%2001-_-Laser%20Printers&pagesize=30", "printer");
                    CategoryUrl.Add("http://www.tigerdirect.ca/applications/Category/guidedSearch.asp?CatId=21&sel=Detail%3B358_1565_84868_84868&cm_re=Printers-_-Spot%2002-_-Inkjet%20Printers&pagesize=30", "printer");
                    CategoryUrl.Add("http://www.tigerdirect.ca/applications/Category/guidedSearch.asp?CatId=25&name=scanners&cm_re=Printers-_-Spot%2003-_-Scanners&pagesize=30", "printer");
                    CategoryUrl.Add("http://www.tigerdirect.ca/applications/category/category_slc.asp?CatId=243&cm_re=Printers-_-Spot%2004-_-Label%20Printers&pagesize=30", "printer");
                    CategoryUrl.Add("http://www.tigerdirect.ca/applications/Category/guidedSearch.asp?CatId=21&sel=Detail%3B358_36_84863_84863&cm_re=Printers-_-Spot%2005-_-Mobile&pagesize=30", "printer");

                }
                catch
                { }
                DisplayRecordProcessdetails("We are going to read product url from category pages for " + chkstorelist.Items[0].ToString() + " Website", "Total  Category :" + CategoryUrl.Count());

                if (File.Exists(Application.StartupPath + "/Files/Url.txt"))
                {
                    FileInfo _Info = new FileInfo(Application.StartupPath + "/Files/Url.txt");
                    int Days = 14;
                    try
                    {
                        Days = Convert.ToInt32(Config.GetAppConfigValue("tigerdirect.ca", "FrequencyOfCategoryScrapping"));
                    }
                    catch
                    {
                    }
                    if (_Info.CreationTime < DateTime.Now.AddDays(-Days))
                        _IsCategorypaging = true;
                    else
                        _IsCategorypaging = false;
                }
                else
                    _IsCategorypaging = true;

                if (_IsCategorypaging)
                {
                    int i = 0;

                    foreach (var Caturl in CategoryUrl)
                    {
                        try
                        {
                            while (_Work.IsBusy && _Work1.IsBusy)
                            {
                                Application.DoEvents();

                            }

                            while (_Stop)
                            {
                                Application.DoEvents();
                            }

                            if (!_Work.IsBusy)
                            {
                                Url1 = Caturl.Key;
                                BrandName1 = Caturl.Value;
                                _Work.RunWorkerAsync();
                            }

                            else
                            {
                                Url2 = Caturl.Key;
                                BrandName2 = Caturl.Value;
                                _Work1.RunWorkerAsync();

                            }

                        }
                        catch { }
                        i++;
                        //if (i == 3)
                        //    break;

                    }
                    while (_Work.IsBusy || _Work1.IsBusy)
                    {
                        Application.DoEvents();

                    }
                    DisplayRecordProcessdetails("We are going to read product url from sub-category pages for " + chkstorelist.Items[0].ToString() + " Website", "Total  Category :" + CategoryUrl.Count());

                    _401index = 0;
                    _IsSubcat = true;
                    foreach (var Caturl in subCategoryUrl)
                    {
                        try
                        {
                            while (_Work.IsBusy && _Work1.IsBusy)
                            {
                                Application.DoEvents();

                            }

                            while (_Stop)
                            {
                                Application.DoEvents();
                            }

                            if (!_Work.IsBusy)
                            {
                                Url1 = Caturl.Key;
                                BrandName1 = Caturl.Value;
                                _Work.RunWorkerAsync();
                            }

                            else
                            {
                                Url2 = Caturl.Key;
                                BrandName2 = Caturl.Value;
                                _Work1.RunWorkerAsync();

                            }

                        }
                        catch (Exception exp)
                        {
                        }

                    }
                }
                while (_Work.IsBusy || _Work1.IsBusy)
                {
                    Application.DoEvents();

                }

                System.Threading.Thread.Sleep(1000);
                _Bar1.Value = 0;
                _401index = 0;

                #region Code to get and write urls from File

                if (File.Exists(Application.StartupPath + "/Files/Url.txt"))
                {
                    using (StreamReader Reader = new StreamReader(Application.StartupPath + "/Files/Url.txt"))
                    {
                        string line = "";
                        while ((line = Reader.ReadLine()) != null)
                        {
                            try
                            {
                                Url.Add(line.Split(new[] { "@#$#" }, StringSplitOptions.None)[0], line.Split(new[] { "@#$#" }, StringSplitOptions.None)[1]);
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                foreach (var url in _ProductUrlthread1)
                {
                    try
                    {
                        if (!Url.Keys.Contains(url.Key.ToLower()))
                            Url.Add(url.Key.ToLower(), url.Value);
                    }
                    catch
                    {
                    }
                }

                foreach (var url in _ProductUrlthread2)
                {
                    try
                    {
                        if (!Url.Keys.Contains(url.Key.ToLower()))
                            Url.Add(url.Key.ToLower(), url.Value);
                    }
                    catch
                    {
                    }
                }

                // Code to write in file
                if (_IsCategorypaging)
                {
                    using (StreamWriter writer = new StreamWriter(Application.StartupPath + "/Files/Url.txt"))
                    {

                        foreach (var PrdUrl in Url)
                        {
                            writer.WriteLine(PrdUrl.Key + "@#$#" + PrdUrl.Value);
                        }
                    }
                }
                #endregion Code to get and write urls from File

                _IsCategorypaging = false;

                DisplayRecordProcessdetails("We are going to read Product information for   " + chkstorelist.Items[0].ToString() + " Website", "Total  products :" + Url.Count());

                _IsProduct = true;

                foreach (var PrdUrl in Url)
                {
                    try
                    {
                        while (_Work.IsBusy && _Work1.IsBusy)
                        {
                            Application.DoEvents();

                        }
                        while (_Stop)
                        {
                            Application.DoEvents();
                        }
                        if (!_Work.IsBusy)
                        {
                            Url1 = PrdUrl.Key;
                            BrandName1 = PrdUrl.Value;
                            _Work.RunWorkerAsync();
                        }
                        else
                        {
                            Url2 = PrdUrl.Key;
                            BrandName2 = PrdUrl.Value;
                            _Work1.RunWorkerAsync();
                        }
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message);
                    }

                }
                while (_Work.IsBusy || _Work1.IsBusy)
                {
                    Application.DoEvents();

                }

                if (Products.Count() > 0)
                {
                    System.Threading.Thread.Sleep(1000);
                    _lblerror.Visible = true;
                    BusinessLayer.ProductMerge _Prd = new BusinessLayer.ProductMerge();
                    _Prd.ProductDatabaseIntegration(Products, "tigerdirect.ca", 1);
                }
                else
                {
                    BusinessLayer.DB _Db = new BusinessLayer.DB();
                    _Db.ExecuteCommand("update Schduler set LastProcessedStatus=0 where StoreName='tigerdirect.ca'");
                    _Mail.SendMail("OOPS there is no any product scrapped by app for tigerdirect.ca Website." + DateTime.Now.ToString(), "Urgent issue in Scrapper.", false, false, 1);

                }
            }
            catch
            {
                BusinessLayer.DB _Db = new BusinessLayer.DB();
                _Db.ExecuteCommand("update Schduler set LastProcessedStatus=0 where StoreName='tigerdirect.ca'");
                _lblerror.Visible = true;
                _Mail.SendMail("Oops Some issue Occured in scrapping data tigerdirect.ca  Website" + DateTime.Now.ToString(), "Urgent issue in Scrapper.", false, false, 1);

            }

            #region closeIEinstance
            try
            {
                _Worker1.Close();
                _Worker2.Close();
            }
            catch
            {
            }
            #endregion closeIEinstance
            #endregion
            _writer.Close();
            this.Close();
        }
Пример #30
0
        public void TestWebUIButton1()
        {
            var input = 123;

            string[] Headers = { "All Numbers:",
                                 "All Odd Numbers:",
                                 "All Even Numbers:",
                                 "All Extended FizzBuzzs:",
                                 "All Fibonacci Numbers:" };

            using (var browser = new WatiN.Core.IE(testUrl))
            {
                browser.TextField(Find.ByName("txtNumber")).TypeText(input.ToString());
                browser.Button(Find.ByName("btnGenerate")).Click();
                browser.WaitForComplete();
                //check each div has content
                var hIdx = 0;

                //sequence objects
                var allNumbers = new AllNumbers();
                var allEven    = new AllEvenNumbers();
                var allOdd     = new AllOddNumbers();
                var allFizz    = new AllExtendedFizzBuzzs();
                var allFib     = new AllFibonacciNumbers();

                foreach (var div in browser.Divs)
                {
                    var h = Headers[hIdx];
                    //check bold txt
                    if (div.Children().Count != 1)
                    {
                        Assert.Fail("Missing or extra bold header of " + h);
                    }
                    else
                    {
                        var boldHeader = div.Children()[0];
                        Assert.IsTrue(boldHeader.OuterHtml.Equals(string.Format("<b>{0}</b>", h)));
                    }

                    switch (hIdx)
                    {
                    case 0:
                        var allNumberSequence = string.Join(", ", allNumbers.CreateSequence(input));
                        Assert.IsTrue(div.Text.Equals(string.Format("{0} {1} ", h, allNumberSequence)));
                        break;

                    case 1:
                        var allOddSequence = string.Join(", ", allOdd.CreateSequence(input));
                        Assert.IsTrue(div.Text.Equals(string.Format("{0} {1} ", h, allOddSequence)));
                        break;

                    case 2:
                        var allEvenSequence = string.Join(", ", allEven.CreateSequence(input));
                        Assert.IsTrue(div.Text.Equals(string.Format("{0} {1} ", h, allEvenSequence)));
                        break;

                    case 3:
                        var allFizzSequence = string.Join(", ", allFizz.CreateSequence(input));
                        Assert.IsTrue(div.Text.Equals(string.Format("{0} {1} ", h, allFizzSequence)));
                        break;

                    case 4:
                        var allFibSequence = string.Join(", ", allFib.CreateSequence(input));
                        Assert.IsTrue(div.Text.Equals(string.Format("{0} {1} ", h, allFibSequence)));
                        break;
                    }
                    hIdx++;
                }
            }
        }
Пример #31
0
        static void GetSpecificContentWithWatin()
        {
            //Kill all ie
            Process[] processes = Process.GetProcessesByName("iexplore");

            foreach (Process process in processes)
            {
                process.Kill();
            }

            HadithDBEntities ctx = new HadithDBEntities();
            var hadist = (from c in ctx.Hadiths
                          where c.HadithID == 1 || c.HadithID == 3 || c.HadithID == 4
                          select c).ToList();
            using (IE ieInstance = new IE())
            {
                // This will open Internet Explorer browser in maximized mode 
                ieInstance.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
                ieInstance.Visible = false;

                ieInstance.WaitForComplete();
                // This will store page source in categoryPageSource variable 

                

                for (int i = 0; i < hadist.Count; i++)
                {
                    var selHadith = hadist[i];
                    var hadistIndex = (from c in ctx.HadithIndexes
                                       where c.HadithID == selHadith.HadithID
                                       && c.No != null
                                       orderby c.No
                                       select c).ToList();
                    for (int j = 0; j < hadistIndex.Count; j++)
                    {
                        var selIndex = hadistIndex[j];
                        var selURL = string.Format("http://sunnah.com/{0}/{1}", selHadith.Name, selIndex.No);

                        try
                        {
                            int HadithOrder = 0;
                            bool isIndonesian = false;
                            bool isUrdu = false;
                            ieInstance.GoTo(selURL);
                            var RdBtn = ieInstance.RadioButton(Find.ById("ch_indonesian"));
                            var RdBtn2 = ieInstance.RadioButton(Find.ById("ch_urdu"));

                            if (ieInstance.Elements.Exists("ch_indonesian") && RdBtn != null)
                            {
                                try
                                {
                                    RdBtn.Click();
                                    ieInstance.WaitForComplete();
                                    Thread.Sleep(500);
                                    // This will wait for the browser to complete loading of the page 
                                    isIndonesian = true;
                                }
                                catch { }
                            }
                            if (ieInstance.Elements.Exists("ch_urdu") && RdBtn2 != null)
                            {
                                try
                                {
                                    RdBtn2.Click();
                                    ieInstance.WaitForComplete();
                                    Thread.Sleep(500);

                                    // This will wait for the browser to complete loading of the page 
                                    isUrdu = true;
                                }
                                catch { }
                            }
                            string HtmlPage = ieInstance.Html;
                            HtmlDocument doc = new HtmlDocument();
                            doc.LoadHtml(HtmlPage);
                            HadithChapter selChapter = null;
                            int ContentCounter = 0;

                            HadithPage selPage = new HadithPage();
                            selPage.PageNo = selIndex.No;
                            selPage.HadithID = selHadith.HadithID;
                            //get title
                            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//div"))
                            {
                                if (node.Attributes["class"] != null && !string.IsNullOrEmpty(node.Attributes["class"].Value))
                                {
                                    switch (node.Attributes["class"].Value)
                                    {
                                        case "book_page_english_name":
                                            selPage.Title = node.InnerText.Trim();
                                            break;
                                        case "book_page_arabic_name arabic":
                                            selPage.TitleArabic = node.InnerText.Trim();
                                            //ctx.HadithPages.Add(selPage);
                                            break;
                                        case "chapter":
                                            selChapter = new HadithChapter();
                                            selChapter.HadithID = selHadith.HadithID;
                                            selChapter.PageNo = selPage.PageNo;
                                            //iterate every chapter
                                            var chapterNode = node;
                                            {
                                                var subnode = chapterNode.SelectSingleNode(".//div[@class='echapno']");
                                                if (subnode != null)
                                                {
                                                    try
                                                    {
                                                        selChapter.ChapterNo = Convert.ToInt32(subnode.InnerText.Trim().Replace("(", "").Replace(")", ""));
                                                    }
                                                    catch
                                                    {
                                                        var Parsed = subnode.InnerText.Trim().Replace("(", "").Replace(")", "");
                                                        if (Parsed.Contains(','))
                                                        {
                                                            selChapter.ChapterNo = Convert.ToInt32(Parsed.Split(',')[0]);
                                                        }
                                                        else
                                                        {
                                                            for (int z = 0; z < Parsed.Length; z++)
                                                            {
                                                                if (!(Parsed[z] >= '0' && Parsed[z] <= '9'))
                                                                {
                                                                    Parsed = Parsed.Replace(Parsed[z].ToString(), " ");
                                                                }
                                                            }
                                                            selChapter.ChapterNo = Convert.ToInt32(Parsed.Trim());
                                                        }
                                                    }
                                                }
                                            }
                                            {
                                                var subnode = chapterNode.SelectSingleNode(".//div[@class='englishchapter']");
                                                if (subnode != null)
                                                {
                                                    selChapter.Title = subnode.InnerText.Trim();
                                                }
                                            }
                                            {
                                                var subnode = chapterNode.SelectSingleNode(".//div[@class='arabicchapter arabic']");
                                                if (subnode != null)
                                                {
                                                    selChapter.TitleArabic = subnode.InnerText.Trim();
                                                }
                                            }
                                            //ctx.HadithChapters.Add(selChapter);
                                            break;
                                        case "arabic achapintro":
                                            {
                                                if (selChapter != null)
                                                {
                                                    selChapter.Intro = node.InnerText.Trim();
                                                }
                                            }
                                            break;
                                        case "actualHadithContainer":
                                            HadithContent selContent = new HadithContent();
                                            selContent.HadithID = selHadith.HadithID;
                                            selContent.PageNo = selPage.PageNo;
                                            selContent.HadithOrder = ++HadithOrder;
                                            if (selChapter != null)
                                            {
                                                selContent.ChapterNo = selChapter.ChapterNo;
                                            }
                                            {
                                                var subnode = node.SelectSingleNode(".//div[@class='hadith_narrated']");
                                                if (subnode != null)
                                                {
                                                    selContent.Narated = subnode.InnerText.Trim();
                                                }
                                            }
                                            {
                                                var subnode = node.SelectSingleNode(".//div[@class='text_details']");
                                                if (subnode != null)
                                                {
                                                    selContent.ContentEnglish = subnode.InnerText.Trim();
                                                }
                                            }
                                            if(isIndonesian)
                                            {
                                                var subnode = node.SelectSingleNode(".//div[@class='indonesian_hadith_full']");
                                                if (subnode != null)
                                                {
                                                    selContent.ContentIndonesia = subnode.InnerText.Trim();
                                                }
                                            }
                                            if (isUrdu)
                                            {
                                                var subnode = node.SelectSingleNode(".//div[@class='urdu_hadith_full']");
                                                if (subnode != null)
                                                {
                                                    selContent.ContentUrdu = subnode.InnerText.Trim();
                                                }
                                            }
                                            {
                                                var subnode = node.SelectSingleNode(".//table[@class='gradetable']");
                                                if (subnode != null)
                                                {
                                                    selContent.Grade = subnode.InnerText.Trim();
                                                }
                                            }
                                            {
                                                var subnode = node.SelectSingleNode(".//table[@class='hadith_reference']");
                                                if (subnode != null)
                                                {
                                                    selContent.Reference = subnode.InnerText.Trim();
                                                }
                                            }
                                            {
                                                var subnode = node.SelectNodes(".//span[@class='arabic_sanad arabic']");
                                                if (subnode != null)
                                                {
                                                    selContent.SanadTop = subnode[0].InnerText.Trim();
                                                    selContent.SanadBottom = subnode[1].InnerText.Trim();
                                                }

                                            }
                                            {
                                                var subnode = node.SelectSingleNode(".//span[@class='arabic_text_details arabic']");
                                                if (subnode != null)
                                                {
                                                    selContent.ContentArabic = subnode.InnerText.Trim();
                                                }
                                            }
                                            ctx.HadithContents.Add(selContent);
                                            ContentCounter++;
                                            if (ContentCounter > 100)
                                            {
                                                ctx.SaveChanges();
                                                ContentCounter = 0;
                                            }
                                            break;
                                        default: break;
                                    }
                                }


                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(selURL + ":" + ex.Message + "-" + ex.StackTrace);
                        }

                        ctx.SaveChanges();
                    }
                }
            }
            Console.WriteLine("selesai");
            Console.ReadLine();
        }
		public static void Descargar(string rfc, string contrasena, string carpeta, DateTime fechaDesde, DateTime fechaHasta, TipoBusqueda busqueda)
		{
			using (IE browser = new IE())
			{
				//limpiar sesion y login 
				browser.ClearCookies();
				Thread.Sleep(1000);

				//java login
				browser.GoTo("https://portalcfdi.facturaelectronica.sat.gob.mx");
				browser.WaitForComplete();

				//entrar por contraseña
				browser.GoTo("https://cfdiau.sat.gob.mx/nidp/app/login?id=SATUPCFDiCon&sid=0&option=credential&sid=0");
				browser.TextField(Find.ByName("Ecom_User_ID")).AppendText(rfc);
				browser.TextField(Find.ByName("Ecom_Password")).AppendText(contrasena);
				browser.Button("submit").Click();

				browser.WaitForComplete();

				//ver si nos pudimos loggear
				if (browser.ContainsText("Login failed, please try again") || browser.ContainsText("La entrada no se ha completado"))
				{
					browser.Close();
					throw new Exception("Los datos de acceso son incorrectos para: " + rfc);
				}

				//seleccionar emitidas o recibidas
				if (busqueda == TipoBusqueda.Emitidas)
				{
					browser.RadioButton("ctl00_MainContent_RdoTipoBusquedaEmisor").Click();
				}
				else
				{
					browser.RadioButton("ctl00_MainContent_RdoTipoBusquedaReceptor").Click();
				}

				browser.Button("ctl00_MainContent_BtnBusqueda").Click();

				Log.Write("Tipo busqueda", Log.Information);

				//Creating the directory if it doesn't exists
				if (!System.IO.Directory.Exists(carpeta))
				{
					System.IO.Directory.CreateDirectory(carpeta);
				}

				//facturas emitidas
				if (busqueda == TipoBusqueda.Emitidas)
				{
					browser.WaitUntilContainsText("Fecha Inicial de Emisión");
					browser.RadioButton("ctl00_MainContent_RdoFechas").Click();
					Thread.Sleep(1000);

					//fecha desde
					browser.TextField("ctl00_MainContent_CldFechaInicial2_Calendario_text").Value = fechaDesde.ToString("dd/MM/yyyy");
					//hasta
					browser.TextField("ctl00_MainContent_CldFechaFinal2_Calendario_text").Value = fechaHasta.ToString("dd/MM/yyyy");
					Thread.Sleep(1000);

					//buscar muchas veces por si marca error de lentitud la pagina del sat >(
					while (true)
					{
						browser.Button("ctl00_MainContent_BtnBusqueda").Click();
						Thread.Sleep(3000);

						if (browser.ContainsText("lentitud"))
						{
							browser.Link("closeBtn").Click();
						}
						else
						{
							break;
						}
					}

					DescargarFacturasListadas(browser, carpeta);
				}
				else
				{
					DateTime mesActual = fechaDesde;
					bool primeraVez = true;

					while (mesActual < fechaHasta)
					{
						browser.WaitUntilContainsText("Fecha de Emisión");
						browser.RadioButton("ctl00_MainContent_RdoFechas").Click();
						Thread.Sleep(1000);

						//seleccionar año adecuado
						browser.SelectList("DdlAnio").SelectByValue(mesActual.Year.ToString());
						//seleccionar mes adecuado
						browser.SelectList("ctl00_MainContent_CldFecha_DdlMes").SelectByValue(mesActual.Month.ToString());

						if (mesActual.Day < 10 && primeraVez)
						{
							//seleccionar dia adecuado
							//click en buscar por que si no no jala
							
							//buscar muchas veces por si marca error de lentitud la pagina del sat >(
							while (true)
							{
								browser.Button("ctl00_MainContent_BtnBusqueda").Click();
								Thread.Sleep(3000);

								if (browser.ContainsText("lentitud"))
								{
									browser.Link("closeBtn").Click();
								}
								else
								{
									break;
								}
							}

							Thread.Sleep(1000);
							primeraVez = false;
						}

						browser.SelectList("ctl00_MainContent_CldFecha_DdlDia").SelectByValue(mesActual.Day.ToString("00"));
						Thread.Sleep(1000);

						//buscar muchas veces por si marca error de lentitud la pagina del sat >(
						while (true)
						{
							browser.Button("ctl00_MainContent_BtnBusqueda").Click();
							Thread.Sleep(3000);

							if (browser.ContainsText("lentitud"))
							{
								browser.Link("closeBtn").Click();
							}
							else
							{
								break;
							}
						}

						DescargarFacturasListadas(browser, carpeta);

						//pasar al siguiente mes
						mesActual = mesActual.AddDays(1);
					}
				}

				browser.Link("ctl00_LnkBtnCierraSesion").Click();
				Thread.Sleep(2000);
				browser.Close();
			}
		}
Пример #33
0
        static string ScrapWebWatin()
        {
            Process[] processes = Process.GetProcessesByName("iexplore");

            foreach (Process process in processes)
            {
                process.Kill();
            }
            // Create an instance of Internet Explorer browser 
            using (IE ieInstance = new IE("http://sunnah.com/bukhari/1"))
            {
                // This will open Internet Explorer browser in maximized mode 
                ieInstance.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowMaximized);
                ieInstance.Visible = false;
                
                ieInstance.WaitForComplete();
                // This will store page source in categoryPageSource variable 

                var RdBtn = ieInstance.RadioButton(Find.ById("ch_indonesian"));
                if (RdBtn != null)
                {
                    RdBtn.Click();
                    // This will wait for the browser to complete loading of the page 

                    string HtmlPage = ieInstance.Html;
                    return HtmlPage;
                }
            }
            return string.Empty;
        }
Пример #34
-2
 public void Purge(IE ie)
 {
     var trash = ie.Page<Trash>();
     ie.GoTo(trash.Url);
     ie.WaitForComplete();
     trash.PurgeAll.Click();
 }