Example #1
0
        public virtual void LoopThroughJobTitles(SimpleHtmlWriter htmlWriter)
        {
            int rowCount = this.table.RowCount;

            Console.WriteLine("The search result page has " + rowCount + " rows.");
            for (int rowIdx = 0; rowIdx < rowCount; rowIdx++)
            {
                try
                {
                    string   vacanciesLinkId = "cphMainContent_OccGrid_lbVacacnyCount_" + rowIdx;
                    TextLink vacanciesLink   = new TextLink(By.Id(vacanciesLinkId));
                    if (vacanciesLink.Exists)
                    {
                        string vacanciesTitle = this.table.GetCell(rowIdx, 0).Text;
                        Console.WriteLine();
                        Console.WriteLine("Clicking the '" + vacanciesTitle + "' vacancies link on row " + rowIdx + " (id=" + vacanciesLinkId + ")");
                        vacanciesLink.Click();

                        (new JobVacancySearchResultsPage()).WaitUntilAvailable().LoopThroughJobVacancies(htmlWriter);

                        Console.WriteLine("Navigate back to the previous (Exams & Job Vacancies Search Results) page");
                        Browser.NavigateBack();
                        WaitUntilAvailable();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }
            }
        }
Example #2
0
        internal void DoSearch(string jobTitle, bool exactMatch, String outputFileName)
        {
            Browser.NavigateTo(HomeUrl);
            JobSearchPage.WaitUntilAvailable();
            JobSearchPage.DoSearch(jobTitle, exactMatch);
            InitialJobSearchResultsPage.WaitUntilAvailable();
            Console.WriteLine("Got 'Exams & Job Vacancies Search Results' page.");

            htmlWriter          = new SimpleHtmlWriter(outputFileName);
            htmlWriter.HtmlHead = htmlHead;

            try
            {
                htmlWriter.BeginHtml();
                htmlWriter.BeginTable();
                InitialJobSearchResultsPage.LoopThroughJobTitles(htmlWriter);
            }
            finally
            {
                htmlWriter.EndTable().EndHtml().Close();
            }
        }
Example #3
0
        public void LoopThroughJobVacancies(SimpleHtmlWriter htmlWriter)
        {
            // Find the list of pages at the table foot.
            IReadOnlyCollection <IWebElement> resultPages = this.table.FindElements(By.CssSelector("tfoot table td"));
            int numOfPages = resultPages.Count;

            if (resultPages.Count == 0)
            {
                numOfPages = 1;
                Console.WriteLine("This 'Job Vacancy Search Results' has only 1 page.");
            }
            else
            {
                numOfPages = resultPages.Count;
                Console.WriteLine("This 'Job Vacancy Search Results' has " + numOfPages + " pages.");
            }

            for (int pageIdx = 0; pageIdx < numOfPages; pageIdx++)
            {
                if (pageIdx > 0)
                {
                    Console.WriteLine("Clicking link to page " + (pageIdx + 1));
                    try
                    {
                        GotoPage(pageIdx);
                    }
                    catch (NoSuchElementException e)
                    {
                        Console.WriteLine("Failed to go into page " + (pageIdx + 1) + " due to exception; skip this page.");
                        Console.WriteLine(e.ToString());
                        Console.Write(e.StackTrace);
                        Console.WriteLine();
                    }
                }
                Console.WriteLine();
                Console.WriteLine("Start parsing page " + (pageIdx + 1));
                int rowCount = this.table.RowCount;
                Console.WriteLine("Page " + (pageIdx + 1) + " lists " + rowCount + " vacancies.");

                for (int rowIdx = 0; rowIdx < rowCount; rowIdx++)
                {
                    try
                    {
                        var    textList        = this.table.GetRow(rowIdx).CellTexts;
                        string jobTitle        = textList[0];
                        string salary          = textList[1];
                        string jobType         = textList[2];
                        string deptAndLocation = textList[3];
                        string postedDate      = textList[4];
                        string deadline        = textList[5];

                        Console.WriteLine("Clicking vacancy " + (rowIdx + 1) + " on page " + (pageIdx + 1));
                        string   postingLinkId = "cphMainContent_grdVacancy_hypJobTitle_" + rowIdx;
                        TextLink postingLink   = new TextLink(By.Id(postingLinkId));
                        postingLink.Click();

                        JobPostPage jobPostPage = new JobPostPage();
                        jobPostPage.WaitUntilAvailable();

                        var details = jobPostPage.GetDetails(jobTitle);
                        jobTitle = details.Item1;
                        string         jobCtrlNumber = details.Item2;
                        IList <string> jobDescTexts  = details.Item3;

                        Console.WriteLine("Writing " + jobCtrlNumber + ": " + jobTitle);
                        var basicInfo = new List <string> {
                            jobCtrlNumber, jobTitle, salary, jobType, deptAndLocation, postedDate, deadline
                        };
                        htmlWriter.WriteTableRow(basicInfo);

                        htmlWriter.Write("<tr><td colspan=\"" + basicInfo.Count + "\">");
                        foreach (string desc in jobDescTexts)
                        {
                            htmlWriter.WriteLine("<p>" + desc + "</p>");
                        }
                        htmlWriter.WriteLine("</td></tr>");

                        Console.WriteLine("Navigate back to the previous (Job Vacancy Search Results) page");
                        Browser.NavigateBack();
                        WaitUntilAvailable();
                    }
                    catch (NoSuchElementException e)
                    {
                        Console.WriteLine(e.ToString());
                        Console.Write(e.StackTrace);
                        //browser.takeScreenShot();
                    }
                }
            }
        }