public static void sb_click(IWebDriver webBrowser, string url, string controlId, bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }
            string html    = webBrowser.PageSource;
            var    control = webBrowser.FindElement(By.Id(controlId));

            if (control != null)
            {
                control.Click();
            }
        }
        public static void sb_readAndSaveToDatatable(IWebDriver webBrowser, string url, string tableId, Model.htmlTable dt
                                                     , bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }

            string html = webBrowser.PageSource;

            if (!string.IsNullOrEmpty(html))
            {
                Functions.sb_fillDatatableWithHtmlTableId(html, tableId, dt);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="loginAndLogout">for those pages which have bugs in access controls</param>
        public void sb_readAllControlsAndSaveToDB(bool loginAndLogout)
        {
            login lg = new login();

            if (loginAndLogout)
            {
                lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
            }
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.prp_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
                this.v_webBrowser.Navigate().GoToUrl(this.prp_url);
            }

            this.sb_readCombosAndSaveToDB();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cycleNumber"></param>
        /// <param name="getExtraDetail">getExtraDetail like fathername and ....</param>
        public void sb_readAllAndSaveToDB(int cycleNumber, bool getExtraDetail)
        {
            login lg = new login();

            lg.fnc_logoutWithSelenium(this.v_webBrowser);
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
            }


            int    pageIndex = 0;
            string html;
            bool   logoutAndLogin = getExtraDetail;

            for (pageIndex = 0; pageIndex <= this.v_pageCount - 1; pageIndex++)
            {
                //if we should get extraDetail we should logout and then login again
                pageIndex = this.fnc_gotoPage(pageIndex, logoutAndLogin);
                if (pageIndex == -1)
                {
                    return;
                }

                html = this.v_webBrowser.PageSource;

                if (!string.IsNullOrEmpty(html))
                {
                    this.v_dtOwners.Rows.Clear();
                    Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, 1, 1, 0, 0, this.v_dtOwners);
                    if (this.v_dtOwners.Rows.Count > 0)
                    {
                        this.sb_saveOwnersDetailsToDB(this.v_dtOwners, cycleNumber);
                    }
                    if (getExtraDetail)
                    {
                        this.sb_readExtraDetailAndSaveToDB(cycleNumber, pageIndex);
                    }
                }
                else
                {
                    break;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="logoutAndLogin">logout current webDriver and login again to see all owners</param>
        /// <returns></returns>
        public int fnc_getPageCount(bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
            }
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
            }

            this.v_webBrowser.Navigate().GoToUrl(this.v_url);
            SharedFunctions.sb_waitForReady(this.v_webBrowser);
            string html          = this.v_webBrowser.PageSource;
            int    lastPageIndex = 0;
            var    table         = Functions.fnc_getElementById(html, this.v_tableId);

            if (table != null)
            {
                var tbody = table.SelectSingleNode("tbody");
                var rows  = tbody.SelectNodes("tr");
                if (rows != null && rows.Count > 0)
                {
                    var lastRow        = rows[rows.Count - 1];
                    var td             = lastRow.SelectSingleNode("td");
                    var hrefCollection = td.SelectNodes("a");
                    if (hrefCollection != null && hrefCollection.Count > 0)
                    {
                        var pageIndexStr = hrefCollection[hrefCollection.Count - 1].InnerText;
                        int temp;
                        if (int.TryParse(pageIndexStr, out temp))
                        {
                            lastPageIndex = temp;
                        }
                    }
                }
            }
            return(lastPageIndex);
        }
        public static int fnc_getPageCountWithRowCount(IWebDriver webBrowser, string url, string controlIdRowCount, string controlIdToClick, bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }

            if (!string.IsNullOrEmpty(controlIdToClick))
            {
                sb_click(webBrowser, url, controlIdToClick, false);
            }
            int lastPageIndex = -1;
            var elRowCount    = webBrowser.FindElement(By.Id(controlIdRowCount));

            //int paginationGroup = 0;
            if (elRowCount != null)
            {
                if (int.TryParse(elRowCount.Text, out lastPageIndex))
                {
                    return(lastPageIndex / v_paginationSize + (lastPageIndex % v_paginationSize > 0 ? 1 : 0));
                }
            }
            return(lastPageIndex);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="logoutAndLogin">logout current webDriver and login again to see all owners</param>
        public int fnc_gotoPage(int pageIndex, bool logoutAndLogin, bool waitTillReady = true)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
            }
            if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
            {
                lg.fnc_loginWithSelenium(this.v_webBrowser);
            }

            if (this.v_pageCount == -1)
            {
                this.v_pageCount = this.fnc_getPageCount(false);
            }
            if (pageIndex > this.v_pageCount)
            {
                return(-1);
            }

            if (pageIndex == 0)
            {
                this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                if (waitTillReady)
                {
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
                return(pageIndex);
            }
            else
            {
                this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                SharedFunctions.sb_waitForReady(this.v_webBrowser);
                var table = this.v_webBrowser.FindElementById(v_tableId);
                if (table != null)
                {
                    var rows = table.FindElements(By.TagName("tr"));
                    if (rows != null && rows.Count > 0)
                    {
                        var lastRow = rows[rows.Count - 1];
                        var td      = lastRow.FindElement(By.TagName("td"));
                        if (td != null)
                        {
                            var hrefCollection = td.FindElements(By.TagName("a"));
                            if (pageIndex <= hrefCollection.Count)
                            {
                                hrefCollection[pageIndex - 1].Click();
                                if (waitTillReady)
                                {
                                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                }
                                return(pageIndex);
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
        }
        public void sb_readAndSaveToDB(bool loginAndLogout, bool getAttach)
        {
            if (loginAndLogout)
            {
                login lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
                if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
                {
                    lg.fnc_loginWithSelenium(this.v_webBrowser);
                    this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
            }

            int    pageIndex = 1;
            int    rowIndex;
            string html;

            using (var entityLogistic = new Model.logisticEntities())
            {
                for (pageIndex = 1; pageIndex <= this.v_pageCount; pageIndex++)
                {
                    Program.logs.Info("Start of :" + pageIndex);
                    //if we should get extraDetail we should logout and then login again
                    if (pageIndex > 1)
                    {
                        pageIndex = seleniumDownloader.fnc_gotoPage(this.v_webBrowser, this.v_url, this.v_tableId, pageIndex, this.v_pageCount, false);
                        if (pageIndex == -1)
                        {
                            return;
                        }
                    }

                    html = this.v_webBrowser.PageSource;

                    if (!string.IsNullOrEmpty(html))
                    {
                        this.v_dt.Rows.Clear();
                        Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, this.v_dt);
                        this.sb_fillDatatablePSID(html, v_tableId, 2, this.v_dt);
                        if (this.v_dt.Rows.Count > 0)
                        {
                            this.sb_saveGroupsToDB(this.v_dt, null);
                        }
                    }
                    else
                    {
                        break;
                    }

                    try
                    {
                        int groupId;
                        for (rowIndex = 0; rowIndex <= this.v_dt.Rows.Count - 1; rowIndex++)
                        {
                            if (Functions.IsNull(this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_id]))
                            {
                                continue;
                            }

                            groupId = int.Parse(this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_id].ToString());

                            var el    = this.v_webBrowser.FindElement(By.Id(this.v_tableId));
                            var rows  = el.FindElements(By.TagName("tr"));
                            var cells = rows[rowIndex + this.v_dt.prp_skipRowTop].FindElements(By.TagName("td"));
                            cells[2].Click();
                            SharedFunctions.sb_waitForReady(this.v_webBrowser);

                            var queryString = HttpUtility.ParseQueryString(this.v_webBrowser.Url);
                            if (!Functions.IsNull(queryString["psid"]))
                            {
                                var entryPartGroup = entityLogistic.rwmmsWagonPartsGroups.FirstOrDefault(o => o.Id == groupId);
                                if (entryPartGroup != null)
                                {
                                    entryPartGroup.wPSID = queryString["psid"];
                                    entityLogistic.SaveChanges();
                                }
                            }
                            this.sb_readAndSavePartsToDB(groupId, this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString(), getAttach
                                                         , this.v_downloadPath);
                            this.sb_readAndSaveSubGroupsToDB(groupId, getAttach, this.v_downloadPath + (this.v_downloadPath.EndsWith("\\") ? "" : "\\") + this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString());

                            var elPath         = this.v_webBrowser.FindElement(By.Id(this.v_pathElementId));
                            var hrefCollection = elPath.FindElements(By.TagName("a"));
                            if (hrefCollection != null && hrefCollection.Count > 0)
                            {
                                hrefCollection[hrefCollection.Count - 1].Click();
                                SharedFunctions.sb_waitForReady(this.v_webBrowser);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    Program.logs.Info("End of :" + pageIndex);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="webBrowser"></param>
        /// <param name="url"></param>
        /// <param name="tableId"></param>
        /// <param name="controlIdToClick">to get pagecount in some pages we need to click a control if this parameter is specified
        /// this function click the control</param>
        /// <param name="logoutAndLogin">for some pages to get all rows we need logoutAndLogin set to true</param>
        /// <returns></returns>
        public static int fnc_getPageCount(IWebDriver webBrowser, string url, By tableBy, string controlIdToClick, bool logoutAndLogin)
        {
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }
            if (!string.IsNullOrEmpty(controlIdToClick))
            {
                sb_click(webBrowser, url, controlIdToClick, false);
            }
            int lastPageIndex = -1;
            int temp, i;

            getPageSource : string html = webBrowser.PageSource;
            var table = webBrowser.FindElement(tableBy);

            //int paginationGroup = 0;
            if (table != null)
            {
                List <IWebElement> rows;
                try
                {
                    var tbody = table.FindElement(By.TagName("tbody"));
                    if (tbody != null)
                    {
                        rows = tbody.FindElements(By.TagName("tr")).ToList();
                    }
                    else
                    {
                        rows = table.FindElements(By.TagName("tr")).ToList();
                    }
                }
                catch
                {
                    rows = table.FindElements(By.TagName("tr")).ToList();
                }

                if (rows != null && rows.Count > 0)
                {
                    //we have atleast one page
                    lastPageIndex = 1;
                    var lastRow        = rows[rows.Count - 1];
                    var td             = lastRow.FindElement(By.TagName("td"));
                    var hrefCollection = td.FindElements(By.TagName("a"));
                    if (hrefCollection != null && hrefCollection.Count > 0)
                    {
                        if (/*v_nextPaginationGroupPos <= hrefCollection.Count
                             * &&*/hrefCollection[hrefCollection.Count - 1].Text == v_nextPaginationText)
                        {
                            //we have next page so we should have next paginationgroup
                            hrefCollection[hrefCollection.Count - 1].Click();
                            SharedFunctions.sb_waitForReady(webBrowser);
                            goto getPageSource;
                            //paginationGroup++;
                        }
                        else
                        {
                            //we do not have nextPaginationGroup
                            for (i = 0; i <= hrefCollection.Count - 1; i++)
                            {
                                if (int.TryParse(hrefCollection[i].Text, out temp))
                                {
                                    if (temp > lastPageIndex)
                                    {
                                        lastPageIndex = temp;
                                    }
                                }
                            }
                            return(lastPageIndex);
                        }
                        //if (hrefCollection.Count < v_paginationSize)
                        //{
                        //    //we do not have next paginiation for example we have only 3 pages and paginzationsize is 10
                        //    var pageIndexStr = hrefCollection[hrefCollection.Count - 1].Text;
                        //    int temp;
                        //    if (int.TryParse(pageIndexStr, out temp))
                        //    {
                        //        lastPageIndex = temp + (paginationGroup * v_paginationSize);
                        //    }
                        //}
                        //else if (hrefCollection.Count > v_paginationSize)
                        //{
                        //    //we have more pages than paginzationsize. e.g. we have 12 pages while paginationsize is 10
                        //    hrefCollection[v_nextPaginationGroupPos].Click();
                        //    SharedFunctions.sb_waitForReady(webBrowser);
                        //    paginationGroup++;

                        //}
                        //else if (hrefCollection.Count == v_paginationSize)
                        //{
                        //    //there are three possibilities paginationsize = 10 and we have 10 pages
                        //    //or we have 19 pages in second group we will have 9 pages and previous button
                        //    //or we have 9 pages  + nextPagination we have 10 hrefCollection
                        //    //so => hrefCollection.Count == v_paginationSize
                        //    if (hrefCollection[v_nextPaginationGroupPos].Text == v_nextPaginationText)
                        //    {
                        //        hrefCollection[v_nextPaginationGroupPos].Click();
                        //        SharedFunctions.sb_waitForReady(webBrowser);
                        //        paginationGroup++;
                        //    }
                        //    else
                        //    {
                        //        var pageIndexStr = hrefCollection[hrefCollection.Count - 1].Text;
                        //        int temp;
                        //        if (int.TryParse(pageIndexStr, out temp))
                        //        {
                        //            lastPageIndex = temp + (paginationGroup * v_paginationSize);
                        //        }
                        //    }
                        //}
                    }
                }
            }
            return(lastPageIndex);
        }
        public static int fnc_gotoPage(IWebDriver webBrowser, string url, By tableBy, int pageIndex, int pageCount, bool logoutAndLogin
                                       , bool waitTillReady = true)
        {
            int i, temp, max, min;

            min = int.MaxValue;
            max = int.MinValue;
            login lg = new login();

            if (logoutAndLogin)
            {
                lg.fnc_logoutWithSelenium(webBrowser);
            }
            if (login.fnc_isLoginPage(webBrowser.Url, url))
            {
                lg.fnc_loginWithSelenium(webBrowser);
                webBrowser.Navigate().GoToUrl(url);
            }

            if (webBrowser.Url.ToLower() != url.ToLower())
            {
                webBrowser.Navigate().GoToUrl(url);
                SharedFunctions.sb_waitForReady(webBrowser);
            }

            if (pageCount == -1)
            {
                pageCount = fnc_getPageCount(webBrowser, url, tableBy, false);
            }
            if (pageIndex > pageCount)
            {
                return(-1);
            }

            if (pageIndex == 1)
            {
                webBrowser.Navigate().GoToUrl(url);
                if (waitTillReady)
                {
                    SharedFunctions.sb_waitForReady(webBrowser);
                }
                return(pageIndex);
            }
            else
            {
                //webBrowser.Navigate().GoToUrl(url);
                //SharedFunctions.sb_waitForReady(webBrowser);
                var table = webBrowser.FindElement(tableBy);
                if (table != null)
                {
                    var rows = table.FindElements(By.TagName("tr"));
                    if (rows != null && rows.Count > 0)
                    {
                        var lastRow = rows[rows.Count - 1];
                        var td      = lastRow.FindElement(By.TagName("td"));
                        if (td != null)
                        {
                            var hrefCollection = td.FindElements(By.TagName("a")).ToList();
                            var hrefCollectionAndCurrentPage = hrefCollection.ToList();
                            hrefCollectionAndCurrentPage.AddRange(td.FindElements(By.TagName("span")).ToList());

                            var hrefPage = hrefCollectionAndCurrentPage.FirstOrDefault(o => o.Text == pageIndex.ToString());
                            if (hrefPage != null)
                            {
                                hrefPage.Click();
                                if (waitTillReady)
                                {
                                    SharedFunctions.sb_waitForReady(webBrowser);
                                }
                                return(pageIndex);
                            }
                            else
                            {
                                for (i = 0; i <= hrefCollectionAndCurrentPage.Count - 1; i++)
                                {
                                    if (int.TryParse(hrefCollectionAndCurrentPage[i].Text, out temp))
                                    {
                                        if (temp < min)
                                        {
                                            min = temp;
                                        }
                                        if (temp > max)
                                        {
                                            max = temp;
                                        }
                                    }
                                }
                                if (min == int.MaxValue || max == int.MinValue)
                                {
                                    //we cannot find any href with integer text
                                    return(-1);
                                }
                                if (min <= pageIndex && pageIndex <= max)
                                {
                                    //page index is between min and max but we could find the page in previous step so there is a problem
                                    return(-1);
                                }
                                if (pageIndex < min)
                                {
                                    //go to previous page
                                    if (hrefCollection.Count >= v_previousPaginationGroupPos &&
                                        hrefCollection[v_previousPaginationGroupPos].Text == v_previousPaginationText)
                                    {
                                        hrefCollection[v_previousPaginationGroupPos].Click();
                                        if (waitTillReady)
                                        {
                                            SharedFunctions.sb_waitForReady(webBrowser);
                                        }

                                        return(fnc_gotoPage(webBrowser, url, tableBy, pageIndex, pageCount, logoutAndLogin));
                                    }
                                }
                                else if (pageIndex > max)
                                {
                                    //go to next page
                                    if (/*hrefCollection.Count >= v_nextPaginationGroupPos
                                         * &&*/hrefCollection[hrefCollection.Count - 1].Text == v_nextPaginationText)
                                    {
                                        hrefCollection[hrefCollection.Count - 1].Click();
                                        if (waitTillReady)
                                        {
                                            SharedFunctions.sb_waitForReady(webBrowser);
                                        }

                                        return(fnc_gotoPage(webBrowser, url, tableBy, pageIndex, pageCount, logoutAndLogin));
                                    }
                                }

                                return(-1);
                            }
                        }
                        else
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
        }
        public void sb_readAndSaveToDB(int cycleNumber, string ownerName, string typeName, bool getLastItems, bool getDetail, bool getAttach, bool loginAndLogout)
        {
            if (loginAndLogout)
            {
                login lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
                if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
                {
                    lg.fnc_loginWithSelenium(this.v_webBrowser);
                    this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                    seleniumDownloader.sb_click(this.v_webBrowser, this.v_url, this.v_buttonSearchId, false);
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
            }

            int    pageIndex = 1;
            string html;
            int    pageIndexStart = 1;

            if (getLastItems)
            {
                using (var entityLogistic = new Model.logisticEntities())
                {
                    int?maxPageNo = entityLogistic.rwmmsDeclerationLists.Where(o => o.wOwnerName == ownerName && o.wTypeName == typeName).Max(o => o.PageIndex);
                    if (maxPageNo.HasValue)
                    {
                        pageIndexStart = maxPageNo.Value;
                    }
                    else
                    {
                        pageIndexStart = 1;
                    }
                }
            }
            for (pageIndex = pageIndexStart; pageIndex <= this.v_pageCount; pageIndex++)
            {
                Program.logs.Info("Start of :" + pageIndex);
                //if we should get extraDetail we should logout and then login again
                if (pageIndex > 1)
                {
                    pageIndex = seleniumDownloader.fnc_gotoPage(this.v_webBrowser, this.v_url, this.v_tableId, pageIndex, this.v_pageCount, false);
                    if (pageIndex == -1)
                    {
                        return;
                    }
                }

                html = this.v_webBrowser.PageSource;

                if (!string.IsNullOrEmpty(html))
                {
                    this.v_dt.Rows.Clear();
                    Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, this.v_dt);
                    if (this.v_dt.Rows.Count > 0)
                    {
                        if (getDetail)
                        {
                            System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> rows;
                            int i = this.v_dt.prp_skipRowTop;
                            do
                            //for (int i = this.v_dt.prp_skipRowTop; i <= rows.Count - this.v_dt.prp_skipRowBottom; i++)
                            {
                                rows = Functions.fnc_getSeleniumTableRows(this.v_webBrowser, this.v_tableId);
                                var cells = rows[i].FindElements(By.TagName("td"));
                                if (cells.Count >= 8)
                                {
                                    cells[8].Click();
                                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                    Functions.sb_fillDataRowWithHtmlControls(this.v_webBrowser.PageSource, this.v_dt, this.v_dt.Rows[i - this.v_dt.prp_skipRowTop]);
                                    try
                                    {
                                        var btnCancel = this.v_webBrowser.FindElement(By.Id("ContentPlaceHolder1_cmdCancel"));
                                        btnCancel.Click();
                                        SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                    }
                                    catch
                                    {
                                        return;
                                    }
                                }
                                i++;
                            } while (i < rows.Count - this.v_dt.prp_skipRowBottom);
                        }

                        if (getAttach)
                        {
                            this.sb_getAttach();
                        }
                        this.sb_saveToDB(this.v_dt, cycleNumber, pageIndex, ownerName, typeName, getDetail, getAttach);
                    }
                }
                else
                {
                    break;
                }
                Program.logs.Info("End of :" + pageIndex);
            }
        }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="webBrowser"></param>
        /// <param name="url"></param>
        /// <param name="grid"></param>
        /// <param name="controlIdToClick">to get pagecount in some pages we need to click a control if this parameter is specified
        /// this function click the control</param>
        /// <param name="logoutAndLogin">for some pages to get all rows we need logoutAndLogin set to true</param>
        /// <returns></returns>
        public static int fnc_getPageCount(IWebDriver webBrowser, string url, IWebElement grid
                                           , IWebElement rowCountElement, string rowCountLabelRegexPattern, int pageRowCount, bool logoutAndLogin)
        {
            if (rowCountElement != null)
            {
                var rowCountStr = rowCountElement.Text;
                int rowCount;
                if (!int.TryParse(rowCountStr, out rowCount))
                {
                    if (!string.IsNullOrEmpty(rowCountLabelRegexPattern))
                    {
                        rowCountStr = System.Text.RegularExpressions.Regex.Replace(rowCountStr, rowCountLabelRegexPattern, "");
                    }
                    rowCountStr = rowCountStr.Replace("&nbsp;", "");
                    rowCountStr = rowCountStr.Replace(" ", "");
                    rowCountStr = rowCountStr.Replace(",", "");
                    rowCountStr = rowCountStr.Replace("تعدادرکورد", "");
                    rowCountStr = rowCountStr.Replace("تعدادركورد", "");
                    rowCountStr = rowCountStr.TrimStart().TrimEnd();
                    rowCount    = int.Parse(rowCountStr);
                }
                return(rowCount / pageRowCount + (rowCount % pageRowCount > 0 ? 1 : 0));
            }
            else
            {
                login lg = new login();
                if (logoutAndLogin)
                {
                    lg.fnc_logoutWithSelenium(webBrowser);
                }
                if (login.fnc_isLoginPage(webBrowser.Url, url))
                {
                    lg.fnc_loginWithSelenium(webBrowser);
                    webBrowser.Navigate().GoToUrl(url);
                }

                if (webBrowser.Url.ToLower() != url.ToLower())
                {
                    webBrowser.Navigate().GoToUrl(url);
                    SharedFunctions.sb_waitForReady(webBrowser);
                }

                int lastPageIndex = -1;
                int temp, i;
                getPageSource : string html = webBrowser.PageSource;

                //int paginationGroup = 0;
                if (grid != null)
                {
                    List <IWebElement> rows;
                    try
                    {
                        var tbody = grid.FindElement(By.TagName("tbody"));
                        if (tbody != null)
                        {
                            rows = tbody.FindElements(By.TagName("tr")).ToList();
                        }
                        else
                        {
                            rows = grid.FindElements(By.TagName("tr")).ToList();
                        }
                    }
                    catch
                    {
                        rows = grid.FindElements(By.TagName("tr")).ToList();
                    }

                    if (rows != null && rows.Count > 0)
                    {
                        //we have atleast one page
                        lastPageIndex = 1;
                        var lastRow        = rows[rows.Count - 1];
                        var td             = lastRow.FindElement(By.TagName("td"));
                        var hrefCollection = td.FindElements(By.TagName("a"));
                        if (hrefCollection != null && hrefCollection.Count > 0)
                        {
                            if (/*v_nextPaginationGroupPos <= hrefCollection.Count
                                 * &&*/hrefCollection[hrefCollection.Count - 1].Text == v_nextPaginationText)
                            {
                                //we have next page so we should have next paginationgroup
                                hrefCollection[hrefCollection.Count - 1].Click();
                                SharedFunctions.sb_waitForReady(webBrowser);
                                goto getPageSource;
                                //paginationGroup++;
                            }
                            else
                            {
                                //we do not have nextPaginationGroup
                                for (i = 0; i <= hrefCollection.Count - 1; i++)
                                {
                                    if (int.TryParse(hrefCollection[i].Text, out temp))
                                    {
                                        if (temp > lastPageIndex)
                                        {
                                            lastPageIndex = temp;
                                        }
                                    }
                                }
                                return(lastPageIndex);
                            }
                        }
                    }
                }
                return(lastPageIndex);
            }
        }