/// <summary> /// Нажимает кнопку на сайте в элементе /// </summary> /// <param name="webControl">webControl на котором будет выполнять метод</param> /// <param name="getElementBy">Атрибут поиска в теге</param> /// <param name="ElementValue">Значение атрибута, по которому будет происходить поиск</param> public void PressButtonInDIV(WebControl webControl, GetElementBy getElementBy, string ElementValue, int count, GetElementBy getElementBy2, string ElementValue2, int count2, string type) { if (getElementBy == GetElementBy.Id) { if (getElementBy2 == GetElementBy.Id) { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + ElementValue + "')." + Elements[getElementBy2] + "('" + ElementValue2 + "')." + type + "()"); } else { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + ElementValue + "')." + Elements[getElementBy2] + "('" + ElementValue2 + "')[" + count2 + "]." + type + "()"); } } else { if (getElementBy2 == GetElementBy.Id) { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + ElementValue + "')[" + count + "]." + Elements[getElementBy2] + "('" + ElementValue2 + "')." + type + "()"); } else { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + ElementValue + "')[" + count + "]." + Elements[getElementBy2] + "('" + ElementValue2 + "')[" + count2 + "]." + type + "()"); } } }
/// <summary> /// Записывает в поле на сайта /// </summary> /// <param name="webControl">webControl на котором будет выполнять метод</param> /// <param name="getElementBy">Атрибут поиска в теге</param> /// <param name="AttributeValue">Значение атрибута, по которому происходит поиск элемента</param> /// <param name="value">Значение, которое запишет в поле на сайте</param> public void WriteInField(WebControl webControl, GetElementBy getElementBy, string AttributeValue, string value) { if (getElementBy == GetElementBy.Id) { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + AttributeValue + "').value = " + "'" + value + "'"); } else { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + AttributeValue + "')[0].value = " + "'" + value + "'"); } }
public void WriteInFieldInDiv(WebControl webControl, GetElementBy getElementBy, string AttributeValue, int count, GetElementBy getElementBy2, string AttributeValue2, int count2, string value) { string js_code; if (getElementBy == GetElementBy.Id) { if (getElementBy2 == GetElementBy.Id) { js_code = "document." + Elements[getElementBy] + "('" + AttributeValue + "')." + Elements[getElementBy2] + "('" + AttributeValue2 + "').value = " + "'" + value + "'"; } else { js_code = "document." + Elements[getElementBy] + "('" + AttributeValue + "')." + Elements[getElementBy2] + "('" + AttributeValue2 + "')[" + count2 + "].value = " + "'" + value + "'"; } } else { if (getElementBy2 == GetElementBy.Id) { js_code = "document." + Elements[getElementBy] + "('" + AttributeValue + "')[" + count + "]." + Elements[getElementBy2] + "('" + AttributeValue2 + "').value = " + "'" + value + "'"; } else { js_code = "document." + Elements[getElementBy] + "('" + AttributeValue + "')[" + count + "]." + Elements[getElementBy2] + "('" + AttributeValue2 + "')[" + count2 + "].value = " + "'" + value + "'"; } } webControl.ExecuteJavascript(js_code); }
public void WbProcentualZoom() { if (!app.Dispatcher.CheckAccess()) { app.Dispatcher.BeginInvoke(new Action(WbProcentualZoom)); return; } if (wb == null || !awesomiumInitialised) { return; } var javascript = string.Format("window.scrollTo(0,{0} * (document.body.scrollHeight - document.body.clientHeight));", ScrollPercentage); try { wb.ExecuteJavascript(javascript); } catch (Exception ex) { Trace.WriteLine(string.Format("Failed to scroll: {0}", ex)); } }
public void CallWeb(string eventName, object data) { if (_web != null && _web.IsDocumentReady) { var jsonData = _serializer.Serialize(data); _web.ExecuteJavascript(string.Format("callWeb('" + eventName + "', {0});", jsonData)); } }
public static void ResizeJavascript(WebControl webControl, float x, float y) { if (!webControl.IsLive) { return; } webControl.ExecuteJavascript("resize(" + Convert.ToString(x).Replace(',', '.') + ", " + Convert.ToString(y).Replace(',', '.') + ")"); }
public static Boolean ByIDSetValue(WebControl webBrowser, String id, String text) { try { if (webBrowser != null) { webBrowser.Invoke(new Action(() => webBrowser.ExecuteJavascript(String.Format("document.getElementById( {0} ).value=\"{1}\";", id, text)))); return(true); } } catch (Exception exception) { exception.Error(); } return(false); }
public static Boolean ClickSubmit(WebControl webBrowser, int index = 0) { try { if (webBrowser != null) { webBrowser.Invoke(new Action(() => webBrowser.ExecuteJavascript(String.Format("document.querySelectorAll(\"button[type='submit']\")[{0}].click();", index)))); return(true); } } catch (Exception exception) { exception.Error(); } return(false); }
public void WbProcentualZoom() { if (!app.Dispatcher.CheckAccess()) { app.Dispatcher.BeginInvoke(new Action(WbProcentualZoom)); return; } if (wb == null) { return; } var javascript = string.Format("window.scrollTo(0,{0} * (document.body.scrollHeight - document.body.clientHeight));", ScrollPercentage); wb.ExecuteJavascript(javascript); }
private void ClickAllPost(WebControl webCtrl, int size) { while (!webCtrl.IsDocumentReady) { Application.DoEvents(); Thread.Sleep(300); } var javascript = @"document.querySelectorAll('div[data-itemid^=\'update\']>div')[{0}].click()"; for (int i = 0; i < size; i++) { string newJs = string.Format(javascript, i); webCtrl.Invoke(new Action(() => { webCtrl.ExecuteJavascript(newJs); // webCtrl.Update(); })); break; // webCtrl.ExecuteJavascriptWithResult(newJs); Thread.Sleep(1500); } }
/// <summary> /// Create a new visual to render. /// </summary> /// <returns></returns> private WebControl CreateRenderable() { // Get the web control. var pControl = new WebControl(); // Create a web-session with our settings. if (pWebSession == null) { pWebSession = WebCore.CreateWebSession(new WebPreferences() { EnableGPUAcceleration = Properties.Settings.Default.EnableGPUAcceleration, Databases = Properties.Settings.Default.EnableWebDatabases, WebGL = Properties.Settings.Default.EnableWebGL, WebSecurity = Properties.Settings.Default.EnableWebSecurity, FileAccessFromFileURL = Properties.Settings.Default.EnableWebFileAccessFromFileURL, Plugins = true, }); } pControl.WebSession = pWebSession; // Set the render dimensions. pControl.Width = this.RenderResolution.X; pControl.Height = this.RenderResolution.Y; // Hide the surface while we load. if (ActiveSurface != null) { ActiveSurface.ContentOpacity = 0.01; } // When the process has been createad, bind the global JS objects. // http://awesomium.com/docs/1_7_rc3/sharp_api/html/M_Awesomium_Core_IWebView_CreateGlobalJavascriptObject.htm pControl.ProcessCreated += (object sender, EventArgs e) => { // CALLING window.Surface = {} in JS here has no effect. // Bind all the Authority.request and Authority.call methods. Log.Write("Display Process Created (1)", this.ToString(), Log.Type.AppError); BindAPIFunctions(pControl); }; UrlEventHandler p = null; p = new UrlEventHandler((object senderOuter, UrlEventArgs eOuter) => { // Unbind this handler. pControl.DocumentReady -= p; // Force a re-load so the $(document).ready will have access to our Authority.request etc. pControl.Reload(false); // CALLING window.Surface = {} in JS here has no effect. //SignalSurfacePropertiesChanged(); Log.Write("Display DocReady (1)", this.ToString(), Log.Type.AppError); // Bind the other events. #region Events // Handle navigating away from the URL in the load instruction. pControl.AddressChanged += (object sender, UrlEventArgs e) => { // Rebind the API methods? Log.Write("Display has changed web address. " + e.Url, this.ToString(), Log.Type.DisplayInfo); }; // Handle console messages. pControl.TitleChanged += (object sender, TitleChangedEventArgs e) => { this.Title = e.Title; }; // Document ready.. do we beat JQuery? pControl.DocumentReady += (object sender, UrlEventArgs e) => { // Show the surface now we are loaded. if (ActiveSurface != null) { ActiveSurface.ContentOpacity = 1.0; } // CALLING window.Surface = {} in JS here does not work quick enough. Log.Write("Display DocReady (2)", this.ToString(), Log.Type.AppError); SignalSurfacePropertiesChanged(); // EXPERIMENTAL - this sort of works.. depends on how the page detects touch events.. // SEE: Nice example: http://paulirish.com/demo/multi // SEE: Nicer example: Bing maps! // Try to inject multi-touch into the page. if (ActiveSurface.AttemptMultiTouchInject) { pControl.ExecuteJavascript(Properties.Resources.MultiTouchInject); } }; // Handle changes in responsiveness. pControl.ResponsiveChanged += (object sender, ResponsiveChangedEventArgs e) => { // If it is not responsive, log the problem. if (!e.IsResponsive) { Log.Write("Display is not responsive. Try reloading.", this.ToString(), Log.Type.DisplayError); //this.Reload(false, true); } else { Log.Write("Ready", this.ToString(), Log.Type.DisplayError); } }; // Handle crashes by reloading. pControl.Crashed += (object sender, CrashedEventArgs e) => { // Log the crash. Log.Write("Display crashed - forcing reload. Termination Status = " + e.Status.ToString(), this.LoadInstruction, Log.Type.DisplayError); // Force a hard-reload. This will remove then re-create the entire web control. this.Reload(true); }; /* * // Handle javascript updates. * pControl.JSConsoleMessageAdded += (object sender, Awesomium.Core.JSConsoleMessageEventArgs e) => * { * Log.Write("JS line " + e.LineNumber + ": " + e.Message, pActiveDisplay.ToString(), Log.Type.DisplayInfo); * }; * * // Handle pop-up messages (like alert). * pControl.ShowPopupMenu += (object sender, PopupMenuEventArgs e) => * { * * }; */ #endregion }); pControl.DocumentReady += p; // Set the load instruction. // n.b. we have to then re-load it later to get access to our value pControl.Source = new Uri(this.LoadInstruction); // Return the created control. return(pControl); }
/// <summary> /// Настраивает фильтр аукциона на определенную категорию /// </summary> /// <param name="wc">Браузер</param> /// <param name="browserValue">Уникальное название категории</param> private static void selectCategory(WebControl wc, string browserValue) { //Выбираем элемент option с названием нужной категории предмета, затем наживаем кнопку OK на форме string jsFunction = "$('[value=\"" + browserValue + "\"]')[0].selected=true;$('[name=\"_filterapply\"]')[0].click();"; wc.ExecuteJavascript(jsFunction); }
/// <summary> /// Выбирает значение из comboBox на сайте /// </summary> /// <param name="webControl">webControl на котором будет выполнять метод</param> /// <param name="getElementBy">Атрибут поиска в теге</param> /// <param name="nuberComboBoxValue">Индекс, по которому выберет значение из comboBox</param> public void SelectComboBoxValue(WebControl webControl, GetElementBy getElementBy, string ElementValue, int nuberComboBoxValue) { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + ElementValue + "').selectedIndex = " + nuberComboBoxValue); }
/// <summary> /// Нажимает кнопку на сайте /// </summary> /// <param name="webControl">webControl на котором будет выполнять метод</param> /// <param name="getElementBy">Атрибут поиска в теге</param> /// <param name="ElementValue">Значение атрибута, по которому будет происходить поиск</param> public void PressButton(WebControl webControl, GetElementBy getElementBy, string ElementValue) { webControl.ExecuteJavascript("document." + Elements[getElementBy] + "('" + ElementValue + "')[0].click()"); }
public static Boolean ByIDSetValue( WebControl webBrowser, String id, String text ) { try { if ( webBrowser != null ) { webBrowser.Invoke( new Action( () => webBrowser.ExecuteJavascript( String.Format( "document.getElementById( {0} ).value=\"{1}\";", id, text ) ) ) ); return true; } } catch ( Exception exception ) { exception.Error(); } return false; }
public bool XPathPickerInject() { wc.ExecuteJavascript(Properties.Resources.JS_ExtractXPath); return(true); }
public static Boolean ClickSubmit( WebControl webBrowser, int index = 0 ) { try { if ( webBrowser != null ) { webBrowser.Invoke( new Action( () => webBrowser.ExecuteJavascript( String.Format( "document.querySelectorAll(\"button[type='submit']\")[{0}].click();", index ) ) ) ); return true; } } catch ( Exception exception ) { exception.Error(); } return false; }
public static void ResizeJavascript(WebControl webControl, float x, float y) { if (!webControl.IsLive) { return; } webControl.ExecuteJavascript("resize(" + Convert.ToString(x).Replace(',', '.') + ", " + Convert.ToString(y).Replace(',', '.') + ")"); }
/// <summary> /// Create a new visual to render. /// </summary> /// <returns></returns> private WebControl CreateRenderable() { // Get the web control. var pControl = new WebControl(); // Create a web-session with our settings. if (pWebSession == null) { pWebSession = WebCore.CreateWebSession(new WebPreferences() { EnableGPUAcceleration = Properties.Settings.Default.EnableGPUAcceleration, Databases = Properties.Settings.Default.EnableWebDatabases, WebGL = Properties.Settings.Default.EnableWebGL, WebSecurity = Properties.Settings.Default.EnableWebSecurity, FileAccessFromFileURL = Properties.Settings.Default.EnableWebFileAccessFromFileURL, Plugins = true, }); } pControl.WebSession = pWebSession; // Set the render dimensions. pControl.Width = this.RenderResolution.X; pControl.Height = this.RenderResolution.Y; // Hide the surface while we load. if (ActiveSurface != null) ActiveSurface.ContentOpacity = 0.01; // When the process has been createad, bind the global JS objects. // http://awesomium.com/docs/1_7_rc3/sharp_api/html/M_Awesomium_Core_IWebView_CreateGlobalJavascriptObject.htm pControl.ProcessCreated += (object sender, EventArgs e) => { // CALLING window.Surface = {} in JS here has no effect. // Bind all the Authority.request and Authority.call methods. Log.Write("Display Process Created (1)", this.ToString(), Log.Type.AppError); BindAPIFunctions(pControl); }; UrlEventHandler p = null; p = new UrlEventHandler((object senderOuter, UrlEventArgs eOuter) => { // Unbind this handler. pControl.DocumentReady -= p; // Force a re-load so the $(document).ready will have access to our Authority.request etc. pControl.Reload(false); // CALLING window.Surface = {} in JS here has no effect. //SignalSurfacePropertiesChanged(); Log.Write("Display DocReady (1)", this.ToString(), Log.Type.AppError); // Bind the other events. #region Events // Handle navigating away from the URL in the load instruction. pControl.AddressChanged += (object sender, UrlEventArgs e) => { // Rebind the API methods? Log.Write("Display has changed web address. " + e.Url, this.ToString(), Log.Type.DisplayInfo); }; // Handle console messages. pControl.TitleChanged += (object sender, TitleChangedEventArgs e) => { this.Title = e.Title; }; // Document ready.. do we beat JQuery? pControl.DocumentReady += (object sender, UrlEventArgs e) => { // Show the surface now we are loaded. if (ActiveSurface != null) ActiveSurface.ContentOpacity = 1.0; // CALLING window.Surface = {} in JS here does not work quick enough. Log.Write("Display DocReady (2)", this.ToString(), Log.Type.AppError); SignalSurfacePropertiesChanged(); // EXPERIMENTAL - this sort of works.. depends on how the page detects touch events.. // SEE: Nice example: http://paulirish.com/demo/multi // SEE: Nicer example: Bing maps! // Try to inject multi-touch into the page. if (ActiveSurface.AttemptMultiTouchInject) { pControl.ExecuteJavascript(Properties.Resources.MultiTouchInject); } }; // Handle changes in responsiveness. pControl.ResponsiveChanged += (object sender, ResponsiveChangedEventArgs e) => { // If it is not responsive, log the problem. if (!e.IsResponsive) { Log.Write("Display is not responsive. Try reloading.", this.ToString(), Log.Type.DisplayError); //this.Reload(false, true); } else { Log.Write("Ready", this.ToString(), Log.Type.DisplayError); } }; // Handle crashes by reloading. pControl.Crashed += (object sender, CrashedEventArgs e) => { // Log the crash. Log.Write("Display crashed - forcing reload. Termination Status = " + e.Status.ToString(), this.LoadInstruction, Log.Type.DisplayError); // Force a hard-reload. This will remove then re-create the entire web control. this.Reload(true); }; /* // Handle javascript updates. pControl.JSConsoleMessageAdded += (object sender, Awesomium.Core.JSConsoleMessageEventArgs e) => { Log.Write("JS line " + e.LineNumber + ": " + e.Message, pActiveDisplay.ToString(), Log.Type.DisplayInfo); }; // Handle pop-up messages (like alert). pControl.ShowPopupMenu += (object sender, PopupMenuEventArgs e) => { }; */ #endregion }); pControl.DocumentReady += p; // Set the load instruction. // n.b. we have to then re-load it later to get access to our value pControl.Source = new Uri(this.LoadInstruction); // Return the created control. return pControl; }