/** * SetupTest used to create a Selenium object and start it * */ private void SetupTest() { string filename = "java"; string parameters = @" -jar selenium-server.jar"; System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcessesByName("java"); try { if (allProcess.Length == 0) { System.Diagnostics.Process.Start(filename, parameters); System.Threading.Thread.Sleep(3000); selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.set.or.th"); selenium.Start(); selenium.SetTimeout("100000"); selenium.UseXpathLibrary("javascript-xpath"); } } catch (System.Exception e) { logger.LogErrorAndRaiseException("Selenium console not started." + e.ToString()); System.Windows.Forms.Application.Exit(); } }
///<summary> ///Start selenium remote controller ///</summary> ///<returns> void </returns> private void StartRC() { string filename = "java"; string parameters = @" -jar selenium-server.jar"; System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcessesByName("java"); try { if (allProcess.Length == 0) { System.Diagnostics.Process.Start(filename, parameters); System.Threading.Thread.Sleep(3000); } selenium1 = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.hkex.com.hk"); selenium1.Start(); selenium1.UseXpathLibrary("javascript-xpath"); } catch (System.Exception e) { MessageBox.Show("Selenium console not started." + e.ToString()); System.Windows.Forms.Application.Exit(); } }
//Start RC server private void startServer() { string filename = "java"; string parameters = @" -jar selenium-server.jar"; System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcessesByName("java"); try { if (allProcess.Length == 0) { System.Diagnostics.Process.Start(filename, parameters); System.Threading.Thread.Sleep(3000); } seleniumInstance = new DefaultSelenium("localhost", 4444, "*iexplore", this.baseUri); seleniumInstance.Start(); seleniumInstance.UseXpathLibrary("javascript-xpath"); } catch (System.Exception e) { Exception friendlyEx = new Exception("Selenium server not started.", e); throw friendlyEx; } }
}//end WarrantDataCapture() ///<summary> ///Recursive Method, start capture data from the breakpoint ///</summary> ///<param name="start_position">Position of ric that interrupted since time out</param> ///<returns> void </returns> private void CaptureRetry(int start_position) { selenium1.Start(); selenium1.UseXpathLibrary("javascript-xpath"); try { selenium1.OpenWindow("/eng/dwrc/newissue/newlaunch.htm", "WarrantListWindow"); selenium1.WaitForPopUp("WarrantListWindow", "30000"); selenium1.SelectWindow("WarrantListWindow"); //Get English Content while (start_position <= endPosition && selenium1.IsElementPresent("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[1]")) { String launchDateStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[11]"); DateTime tempLaunchDateDT = DateTime.ParseExact(launchDateStr, "dd-MM-yyyy", null); DateTime temp = coreObj.DateCalculate(scheduleDate, tempLaunchDateDT, holidayCount); if (temp.Date == scheduleDate.Date) { HKRicTemplate hkRic = new HKRicTemplate(); hkRic.launchDateDT = DateTime.ParseExact(launchDateStr, "dd-MM-yyyy", null); hkRic.ricCodeStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[2]"); hkRic.ricNameStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[3]"); hkRic.issuerIDStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[4]"); hkRic.underlyingStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[5]"); hkRic.callPutStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[6]"); hkRic.boardLotStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[7]"); hkRic.strikeLevelStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[8]"); hkRic.entitlementRatioStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[9]"); hkRic.issueSizeStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[10]"); hkRic.clearingCommDateDT = DateTime.ParseExact(selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[12]"), "dd-MM-yyyy", null); hkRic.listingDateDT = DateTime.ParseExact(selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[13]"), "dd-MM-yyyy", null); hkRic.maturityDateDT = DateTime.ParseExact(selenium1.GetText("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[14]"), "dd-MM-yyyy", null); //Get issue price String url = selenium1.GetAttribute("//table[@id='bodytable']/tbody/tr/td/table/tbody[1]/tr[" + start_position + "]/td[2]/a@href"); String id = url.Substring(url.IndexOf('=') + 1, 5); String summaryUrl = "http://www.hkex.com.hk/eng/dwrc/dwsummary.asp?id=" + id; selenium1.OpenWindow(summaryUrl, "WarrantSummaryWindow" + start_position); selenium1.WaitForPopUp("WarrantSummaryWindow" + start_position, "30000"); selenium1.SelectWindow("WarrantSummaryWindow" + start_position); //For Equity Get underlying name if (Char.IsDigit(hkRic.underlyingStr, 0)) { hkRic.underlyingNameForStockStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr[3]/td[2]").Substring(8); } hkRic.issuePriceStr = selenium1.GetText("//table[@id='bodytable']/tbody/tr[11]/td[2]").Substring(4); selenium1.Close(); ricList.Add(hkRic); selenium1.SelectWindow("WarrantListWindow"); }//end if start_position++; }//end while ChineseNameCapture(start_position); //Get gearing and premium //search on page http://www.hkexnews.hk/listedco/listconews/advancedsearch/search_active_main.asp DataCaptureFromPDF(0); }//end try catch (SeleniumException ex) { String errLog = ex.ToString(); selenium1.Close(); selenium1.Stop(); CaptureRetry(start_position); } }