private void ExecJsScript() { UtilsLog.Log("ExecJsScript ENTER"); //GetWindowDevicePixelRatio(); //GetDocumentScrollLeft(); //GetDocumentScrollTop(); }
private void RunLoopMainStep11() { HtmlElement elemreactselect5value = webBrowser1.Document.GetElementById("react-select-5--value"); UtilsLog.Log("RunLoopMainStep11 elemreactselect5value={0}", elemreactselect5value); if (elemreactselect5value == null) { return; } int scrollLeft = GetDocumentScrollLeft(); int scrollTop = GetDocumentScrollTop(); UtilsLog.Log("RunLoopMainStep11 scrollLeft={0} scrollTop={1}", scrollLeft, scrollTop); double devicePixelRatio = GetWindowDevicePixelRatio(); UtilsLog.Log("RunLoopMainStep11 devicePixelRatio={0}", devicePixelRatio); Point elementPosition = UtilsHtml.GetHtmlElementScreenPosition(elemreactselect5value, scrollLeft, scrollTop); elementPositionX = (int)(elementPosition.X * devicePixelRatio); elementPositionY = (int)(elementPosition.Y * devicePixelRatio); elementPositionX += 20; elementPositionY += 10; UtilsLog.Log("RunLoopMainStep11 elementPositionX={0} elementPositionY={1}", elementPositionX, elementPositionY); UtilsLog.Log("RunLoopMainStep11 comboBox1.SelectedIndex={0}", comboBox1.SelectedIndex); elementPositionY += (comboBox1.SelectedIndex + 1) * 68; MouseEvent.EventMouseMove(elementPositionX, elementPositionY); Thread.Sleep(500); MouseEvent.EventMouseClick(elementPositionX, elementPositionY); step++; }
private void RunLoopMainStep9() { UtilsLog.Log("RunLoopMainStep9 ENTER"); HtmlElement elemreactselect5value = webBrowser1.Document.GetElementById("react-select-5--value"); if (elemreactselect5value == null) { return; } elemreactselect5value.Focus(); RunLoopSleep(2000); string funcName; string funcBody; funcName = "getWindowDevicePixelRatio"; funcBody = "{return window.devicePixelRatio;}"; CreateJsFunc(funcName, funcBody); funcName = "getDocumentScrollLeft"; funcBody = "{return document.documentElement.scrollLeft;}"; CreateJsFunc(funcName, funcBody); funcName = "getDocumentScrollTop"; funcBody = "{return document.documentElement.scrollTop;}"; CreateJsFunc(funcName, funcBody); ForegroundWindow(); step++; }
private void RunLoopMainStep2() { UtilsLog.Log("RunLoopMainStep2 ENTER"); HtmlElement eledxpdateselectionview = webBrowser1.Document.GetElementById("dxp-date-selection-view"); if (eledxpdateselectionview != null) { List <HtmlElement> eledxpdateselectionviewItems = new List <HtmlElement>(); UtilsHtml.FindElementHtmlElements(eledxpdateselectionview, ":div/:div/:div/:div/class:page-messages/:div/class:title-container/:div/class:title/:span", eledxpdateselectionviewItems); if (eledxpdateselectionviewItems.Count > 0) { HtmlElement elemappItem = eledxpdateselectionviewItems[0]; if (elemappItem.InnerText.Contains("未找到航班")) { //失败 RunLoopSleep(5000); step++; } } } HtmlElement eledxpflighttablesection = webBrowser1.Document.GetElementById("dxp-flight-table-section"); if (eledxpflighttablesection != null) { //成功 RunLoopSleep(2000); step += 3; } }
private void RunLoopMainStep3() { UtilsLog.Log("RunLoopMainStep3 ENTER"); webBrowser1.Navigate(url); RunLoopSleep(3000); step++; }
public static void PrintFrameWindowName(WebBrowser web) { HtmlWindow webWindow = web.Document.Window; UtilsLog.Log("PrintFrameWindowName ENTER Count= " + webWindow.Frames.Count); for (int i = 0; i < webWindow.Frames.Count; i++) { PrintFrameWindowNameFrame(i, webWindow.Frames[i]); } }
private int GetDocumentScreenLeft() { object retnGetDocumentScreenLeft = ExecJSFunc("getDocumentScreenLeft"); UtilsLog.Log("GetDocumentScreenLeft retnGetDocumentScreenLeft={0} {1}", retnGetDocumentScreenLeft.GetType(), retnGetDocumentScreenLeft.ToString()); int screenLeft = Convert.ToInt32(retnGetDocumentScreenLeft); UtilsLog.Log("GetDocumentScreenLeft screenLeft={0}", screenLeft); return(screenLeft); }
public static void PrintFrameWindowNameFrame(int index, HtmlWindow frame) { try { UtilsLog.Log("PrintFrameWindowNameFrame [" + index.ToString() + "]=" + frame.Name); } catch (Exception e) { //UtilsLog.Log("PrintFrameWindowNameFrame EXCEPTION " + e.Message); } }
private void RunLoopMainEx() { try { RunLoopMain(); } catch (Exception e) { UtilsLog.Log("RunLoopMainEx EXCEPTION" + e.Message); } }
public static void EventMouseMove(int x, int y) { UtilsLog.Log("EventMouseMove ENTER " + "X=" + x.ToString() + " Y=" + y.ToString()); //SetCursorPos(x, y); int mx = x * 65535 / GetSystemMetrics(SM_CXSCREEN); int my = y * 65535 / GetSystemMetrics(SM_CYSCREEN); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, mx, my, 0, 0); Thread.Sleep(100); }
private int GetDocumentScrollTop2(string elemId) { UtilsLog.Log("GetDocumentScrollTop2 ENTER {0}", elemId); object retnGetDocumentScrollTop = ExecJSFuncWithParam1("getDocumentScrollTop2", elemId); UtilsLog.Log("GetDocumentScrollTop2 retnGetDocumentScrollTop={0} {1}", retnGetDocumentScrollTop.GetType(), retnGetDocumentScrollTop.ToString()); double scrollTop = Convert.ToDouble(retnGetDocumentScrollTop); return((int)scrollTop); }
private int GetDocumentScrollTop() { UtilsLog.Log("GetDocumentScrollTop ENTER"); object retnGetDocumentScrollTop = ExecJSFunc("getDocumentScrollTop"); UtilsLog.Log("GetDocumentScrollTop retnGetDocumentScrollTop={0} {1}", retnGetDocumentScrollTop.GetType(), retnGetDocumentScrollTop.ToString()); int scrollTop = Convert.ToInt32(retnGetDocumentScrollTop); UtilsLog.Log("GetDocumentScrollTop scrollTop={0}", scrollTop); return(scrollTop); }
private double GetWindowDevicePixelRatio() { UtilsLog.Log("GetWindowDevicePixelRatio ENTER"); object retngetWindowDevicePixelRatio = ExecJSFunc("getWindowDevicePixelRatio"); UtilsLog.Log("GetWindowDevicePixelRatio retngetWindowDevicePixelRatio={0} {1}", retngetWindowDevicePixelRatio.GetType(), retngetWindowDevicePixelRatio.ToString()); double devicePixelRatio = Convert.ToDouble(retngetWindowDevicePixelRatio); return(devicePixelRatio); }
public static Point GetHtmlElementScreenPosition(HtmlElement element) { Point p = new Point(); p.X = 0; p.Y = 0; List <HtmlElement> elements = new List <HtmlElement>(); HtmlElement nextElement = element; while (nextElement != null) { elements.Add(nextElement); nextElement = nextElement.OffsetParent; } elements.Reverse(); foreach (HtmlElement currElement in elements) { p.X += currElement.OffsetRectangle.Left; p.Y += currElement.OffsetRectangle.Top; string currElementTag = currElement.TagName; string currElementClassName = currElement.GetAttribute("className"); string currElementId = currElement.Id; UtilsLog.Log("GetHtmlElementScreenPosition p={0} {1} tag={2} class={3} id={4}", p.X, p.Y, currElementTag, currElementClassName, currElementId); } UtilsLog.Log("GetHtmlElementScreenPosition ScrollLeft={0} ScrollTop={1}", element.Document.Body.ScrollLeft, element.Document.Body.ScrollTop); p.X -= element.Document.Body.ScrollLeft; p.Y -= element.Document.Body.ScrollTop; UtilsLog.Log("GetHtmlElementScreenPosition p={0} {1}", p.X, p.Y); UtilsLog.Log("GetHtmlElementScreenPosition OffsetRectangle={0} {1}", element.OffsetRectangle.Width, element.OffsetRectangle.Height); p.X += element.OffsetRectangle.Width / 2; p.Y += element.OffsetRectangle.Height / 2; UtilsLog.Log("GetHtmlElementScreenPosition p={0} {1}", p.X, p.Y); HtmlWindow window = element.Document.Window; UtilsLog.Log("GetHtmlElementScreenPosition window.Position={0} {1}", window.Position.X, window.Position.Y); p.X += window.Position.X; p.Y += window.Position.Y; UtilsLog.Log("GetHtmlElementScreenPosition p={0} {1}", p.X, p.Y); return(p); }
private void RunLoopMainStep4() { UtilsLog.Log("RunLoopMainStep4 ENTER"); HtmlElement elemflightsearchcopy = webBrowser1.Document.GetElementById("flightsearch_copy"); if (elemflightsearchcopy == null) { return; } step = 0; }
private void RunLoopMainStep14() { UtilsLog.Log("RunLoopMainStep14 ENTER"); if (beep_count == 0) { step++; return; } Beep(500, 700); beep_count--; }
public static void EventMouseClick(int x, int y) { UtilsLog.Log("EventMouseClick ENTER " + "X=" + x.ToString() + "Y=" + y.ToString()); int mx = x * 65535 / GetSystemMetrics(SM_CXSCREEN); int my = y * 65535 / GetSystemMetrics(SM_CYSCREEN); mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, mx, my, 0, 0); Thread.Sleep(100); mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE, mx, my, 0, 0); Thread.Sleep(100); mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE, mx, my, 0, 0); }
public void CreateJsFuncWithParam2(string funcName, string param1, string param2, string funcBody) { UtilsLog.Log("CreateJsFunc ENTER {0}", funcName); HtmlDocument document = webBrowser1.Document; string funcText = "function " + funcName + "(" + param1 + ", " + param2 + "){" + funcBody + "}"; HtmlElement elementScript = document.CreateElement("script"); elementScript.SetAttribute("type", "text/javascript"); elementScript.SetAttribute("text", funcText); HtmlElement elementHead = document.GetElementsByTagName("head")[0]; elementHead.AppendChild(elementScript); }
private void RunLoopMainStep1() { UtilsLog.Log("RunLoopMainStep1 ENTER"); List <HtmlElement> elems = new List <HtmlElement>(); UtilsHtml.FindWindowHtmlElementsByTagAndText(webBrowser1.Document.Window, "button", "搜索航班", elems); if (elems.Count > 0) { elems[0].Focus(); elems[0].InvokeMember("click"); RunLoopSleep(2000); step++; } }
public static void SaveHtmlWindowHtmlSource(HtmlWindow window, string fileName) { UtilsLog.Log("SaveHtmlWindowHtmlSource ENTER " + fileName); try { FileStream fs = new FileStream(fileName, FileMode.Create); string source = Utf8ToGB2312(window.Document.Body.OuterHtml); byte[] bytes = Encoding.UTF8.GetBytes(source); fs.Write(bytes, 0, bytes.Length); fs.Close(); } catch (Exception e) { UtilsLog.Log("SaveHtmlWindowHtmlSource EXCEPTION " + e.Message); } }
private void RunLoopMainStep6() { UtilsLog.Log("RunLoopMainStep6 ENTER"); HtmlElement elemFlight = elemFlights[0]; List <HtmlElement> elemFlightItems = new List <HtmlElement>(); UtilsHtml.FindElementHtmlElements(elemFlight, ":div/:div/:div/class:itinerary-part-offer-price/class:price-content-wrapper/data-test-id:cabin-offer-button", elemFlightItems); UtilsLog.Log("RunLoopMainStep6 elemFlightItems.Count={0}", elemFlightItems.Count); if (elemFlightItems.Count > 0) { elemFlightItems[0].Focus(); elemFlightItems[0].InvokeMember("click"); RunLoopSleep(2000); step++; } }
private void RunLoopMainStep7() { UtilsLog.Log("RunLoopMainStep7 ENTER"); HtmlElement elemFlight = elemFlights[0]; List <HtmlElement> elemFlightItems = new List <HtmlElement>(); UtilsHtml.FindElementHtmlElements(elemFlight, ":div/:div/class:shadow-box/:div/:div/class:brand-selection-button-container/:div/:button", elemFlightItems); UtilsLog.Log("RunLoopMainStep7 elemFlightItems.Count={0}", elemFlightItems.Count); if (elemFlightItems.Count > 0) { elemFlightItems[0].Focus(); elemFlightItems[0].InvokeMember("click"); RunLoopSleep(2000); step++; } }
private void RunLoopMainStep0() { UtilsLog.Log("RunLoopMainStep0 ENTER"); //InitJsScript(); //ExecJsScript(); HtmlElement elemoneWay = webBrowser1.Document.GetElementById("oneWay"); if (elemoneWay == null) { return; } elemoneWay.Focus(); elemoneWay.InvokeMember("click"); step++; }
private void RunLoopMainStep5() { UtilsLog.Log("RunLoopMainStep5 ENTER"); HtmlElement eledxpflighttablesection = webBrowser1.Document.GetElementById("dxp-flight-table-section"); if (eledxpflighttablesection == null) { return; } elemFlights.Clear(); foreach (HtmlElement eledxpflighttablesectionChild in eledxpflighttablesection.Children) { string eledxpflighttablesectionChildClassName = eledxpflighttablesectionChild.GetAttribute("className"); if (eledxpflighttablesectionChildClassName.Contains("ducp-component-panel") && eledxpflighttablesectionChildClassName.Contains("spark-panel") && eledxpflighttablesectionChildClassName.Contains("itinerary-part-offer")) { elemFlights.Add(eledxpflighttablesectionChild); } } if (elemFlights.Count > 0) { if (comboBox2.Text == "商务舱") { HtmlElement elemFlight = elemFlights[0]; List <HtmlElement> elemFlightItems = new List <HtmlElement>(); UtilsHtml.FindElementHtmlElements(elemFlight, ":div/:div/:div/:button", elemFlightItems); foreach (HtmlElement elemFlightItem in elemFlightItems) { if (elemFlightItem.InnerText.Contains("下一個")) { elemFlightItem.Focus(); elemFlightItem.InvokeMember("click"); } } } RunLoopSleep(2000); step++; } }
public static void SaveWebBrowserHtmlSource(WebBrowser web) { string[] urlNameLists = web.Document.Url.AbsoluteUri.Split('/'); string urlLastName = urlNameLists[urlNameLists.Length - 1]; string[] urlTitleLists = urlLastName.Split('.'); string urlTitleName = urlTitleLists[0]; DateTime dateTime = DateTime.Now; string fileDir = System.Environment.CurrentDirectory; UtilsLog.Log("SaveWebBrowserHtmlSource fileDir=" + fileDir); string saveDir = fileDir + "\\html\\" + dateTime.Year.ToString("D4") + dateTime.Month.ToString("D2") + dateTime.Day.ToString("D2") + "_" + dateTime.Hour.ToString("D2") + dateTime.Minute.ToString("D2") + dateTime.Second.ToString("D2"); Directory.CreateDirectory(saveDir); UtilsLog.Log("SaveWebBrowserHtmlSource saveDir=" + saveDir); string fileName = saveDir + "\\" + urlTitleName + ".txt"; SaveHtmlWindowHtmlSource(web.Document.Window, fileName); HtmlWindow webWindow = web.Document.Window; foreach (HtmlWindow frame in webWindow.Frames) { try { string frameFileName = saveDir + "\\Frame_" + frame.Name + ".txt"; SaveHtmlWindowHtmlSource(frame, frameFileName); } catch (Exception e) { UtilsLog.Log("SaveWebBrowserHtmlSource EXCEPTION " + e.Message); } } }
private void RunLoopMainStep8() { UtilsLog.Log("RunLoopMainStep8 ENTER"); HtmlElement eledxpsharedflightselection = webBrowser1.Document.GetElementById("dxp-shared-flight-selection"); if (eledxpsharedflightselection != null) { List <HtmlElement> eledxpsharedflightselectionItems = new List <HtmlElement>(); UtilsHtml.FindElementHtmlElements(eledxpsharedflightselection, ":div/:div/:button", eledxpsharedflightselectionItems); UtilsLog.Log("RunLoopMainStep8 eledxpsharedflightselection.Count={0}", eledxpsharedflightselectionItems.Count); foreach (HtmlElement eledxpsharedflightselectionItem in eledxpsharedflightselectionItems) { if (eledxpsharedflightselectionItem.InnerText == "乘客") { eledxpsharedflightselectionItem.Focus(); eledxpsharedflightselectionItem.InvokeMember("click"); RunLoopSleep(2000); step++; } } } }
private void RunLoopMainStep13() { UtilsLog.Log("RunLoopMainStep13 ENTER"); HtmlElement elempaymentcreditcardform = webBrowser1.Document.GetElementById("payment-credit-card-form"); if (elempaymentcreditcardform != null) { beep_count = 5; RunLoopSleep(2000); step++; return; } HtmlElement elemdxppagenavigationcontinuebutton = webBrowser1.Document.GetElementById("dxp-page-navigation-continue-button"); UtilsLog.Log("RunLoopMainStep13 elemdxppagenavigationcontinuebutton={0}", elemdxppagenavigationcontinuebutton); if (elemdxppagenavigationcontinuebutton != null) { elemdxppagenavigationcontinuebutton.Focus(); elemdxppagenavigationcontinuebutton.InvokeMember("click"); } }
private void RunLoopMainStep15() { UtilsLog.Log("RunLoopMainStep15 ENTER"); }
private void RunLoopMainStep12() { UtilsLog.Log("RunLoopMainStep12 ENTER"); HtmlElement elemfirstNamePassengerItemAdt1BasicInfoEditFirstName = webBrowser1.Document.GetElementById("firstNamePassengerItemAdt1BasicInfoEditFirstName-passenger-item-ADT-1-basic-info-edit"); UtilsLog.Log("RunLoopMainStep12 elemfirstNamePassengerItemAdt1BasicInfoEditFirstName={0}", elemfirstNamePassengerItemAdt1BasicInfoEditFirstName); HtmlElement elemlastNamePassengerItemAdt1BasicInfoEditLastName = webBrowser1.Document.GetElementById("lastNamePassengerItemAdt1BasicInfoEditLastName-passenger-item-ADT-1-basic-info-edit"); UtilsLog.Log("RunLoopMainStep12 elemlastNamePassengerItemAdt1BasicInfoEditLastName={0}", elemlastNamePassengerItemAdt1BasicInfoEditLastName); HtmlElement elemphoneDefault = webBrowser1.Document.GetElementById("phoneDefaultInput-undefined-additional-contact-info-phone"); UtilsLog.Log("RunLoopMainStep12 elemphoneDefault={0}", elemphoneDefault); HtmlElement elememailAdditionalContactInfoEmailEmail = webBrowser1.Document.GetElementById("emailAdditionalContactInfoEmailEmail-additional-contact-info-email"); UtilsLog.Log("RunLoopMainStep12 elememailAdditionalContactInfoEmailEmail={0}", elememailAdditionalContactInfoEmailEmail); if (elemfirstNamePassengerItemAdt1BasicInfoEditFirstName == null || elemlastNamePassengerItemAdt1BasicInfoEditLastName == null || elemphoneDefault == null || elememailAdditionalContactInfoEmailEmail == null) { return; } HtmlElement elemreactselect5value = webBrowser1.Document.GetElementById("react-select-5--value"); UtilsLog.Log("RunLoopMainStep12 elemreactselect5value={0}", elemreactselect5value); if (elemreactselect5value == null) { return; } HtmlElement elemreactselect5valueitem = webBrowser1.Document.GetElementById("react-select-5--value-item"); UtilsLog.Log("RunLoopMainStep12 elemreactselect5valueitem={0}", elemreactselect5valueitem); if (elemreactselect5valueitem == null) { //elemreactselect5value.Children[0].InvokeMember("click"); return; } BookSetting bookSetting = GetBookSetting(); if (elemfirstNamePassengerItemAdt1BasicInfoEditFirstName.GetAttribute("value") == "") { elemfirstNamePassengerItemAdt1BasicInfoEditFirstName.Focus(); elemfirstNamePassengerItemAdt1BasicInfoEditFirstName.SetAttribute("value", bookSetting.lastName); } else if (elemlastNamePassengerItemAdt1BasicInfoEditLastName.GetAttribute("value") == "") { elemlastNamePassengerItemAdt1BasicInfoEditLastName.Focus(); elemlastNamePassengerItemAdt1BasicInfoEditLastName.SetAttribute("value", bookSetting.firstName); } else if (elemphoneDefault.GetAttribute("value").Length < 6) { elemphoneDefault.Focus(); elemphoneDefault.SetAttribute("value", bookSetting.telephone); } else if (elememailAdditionalContactInfoEmailEmail.GetAttribute("value") == "") { elememailAdditionalContactInfoEmailEmail.Focus(); elememailAdditionalContactInfoEmailEmail.SetAttribute("value", bookSetting.email); } else { HtmlElement elemdxppassengerviewskip = webBrowser1.Document.GetElementById("dxp-passenger-view-skip"); if (elemdxppassengerviewskip != null) { elemdxppassengerviewskip.Focus(); elemdxppassengerviewskip.InvokeMember("click"); RunLoopSleep(3000); step++; return; } } }
public void RunLoopSleep(int timeout) { UtilsLog.Log("RunLoopSleep ENTER {0}", timeout); sleep += timeout; }