/// <summary> /// Raises the <see cref="ScriptExecuted"/> event. /// </summary> /// <param name="e">A <see cref="WebDriverScriptEventArgs"/> that contains the event data.</param> protected virtual void OnScriptExecuted(WebDriverScriptEventArgs e) { if (this.ScriptExecuted != null) { this.ScriptExecuted(this, e); } }
public object ExecuteScript(string script, params object[] args) { IJavaScriptExecutor javaScriptExecutor = this.driver as IJavaScriptExecutor; if (javaScriptExecutor == null) { throw new NotSupportedException("Underlying driver instance does not support executing JavaScript"); } object result = null; try { object[] args2 = EventFiringWebDriver.UnwrapElementArguments(args); WebDriverScriptEventArgs e = new WebDriverScriptEventArgs(this.driver, script); this.OnScriptExecuting(e); result = javaScriptExecutor.ExecuteScript(script, args2); this.OnScriptExecuted(e); } catch (Exception thrownException) { this.OnException(new WebDriverExceptionEventArgs(this.driver, thrownException)); throw; } return(result); }
/// <summary> /// Executes JavaScript asynchronously in the context of the currently selected frame or window. /// </summary> /// <param name="script">The JavaScript code to execute.</param> /// <param name="args">The arguments to the script.</param> /// <returns>The value returned by the script.</returns> public object ExecuteAsyncScript(string script, params object[] args) { IJavaScriptExecutor javascriptDriver = this.driver as IJavaScriptExecutor; if (javascriptDriver == null) { throw new NotSupportedException("Underlying driver instance does not support executing javascript"); } object[] unwrappedArgs = UnwrapElementArguments(args); WebDriverScriptEventArgs e = new WebDriverScriptEventArgs(this.driver, script); this.OnScriptExecuting(e); object scriptResult = javascriptDriver.ExecuteAsyncScript(script, unwrappedArgs); this.OnScriptExecuted(e); return(scriptResult); }
/// <summary> /// Raises the <see cref="ScriptExecuting"/> event. /// </summary> /// <param name="e">A <see cref="WebDriverScriptEventArgs"/> that contains the event data.</param> protected virtual void OnScriptExecuting(WebDriverScriptEventArgs e) { if (this.ScriptExecuting != null) { this.ScriptExecuting(this, e); } }
/// <summary> /// Executes JavaScript in the context of the currently selected frame or window. /// </summary> /// <param name="script">The JavaScript code to execute.</param> /// <param name="args">The arguments to the script.</param> /// <returns>The value returned by the script.</returns> /// <remarks> /// <para> /// The <see cref="ExecuteScript"/>method executes JavaScript in the context of /// the currently selected frame or window. This means that "document" will refer /// to the current document. If the script has a return value, then the following /// steps will be taken: /// </para> /// <para> /// <list type="bullet"> /// <item><description>For an HTML element, this method returns a <see cref="IWebElement"/></description></item> /// <item><description>For a number, a <see cref="System.Int64"/> is returned</description></item> /// <item><description>For a boolean, a <see cref="System.Boolean"/> is returned</description></item> /// <item><description>For all other cases a <see cref="System.String"/> is returned.</description></item> /// <item><description>For an array,we check the first element, and attempt to return a /// <see cref="List{T}"/> of that type, following the rules above. Nested lists are not /// supported.</description></item> /// <item><description>If the value is null or there is no return value, /// <see langword="null"/> is returned.</description></item> /// </list> /// </para> /// <para> /// Arguments must be a number (which will be converted to a <see cref="System.Int64"/>), /// a <see cref="System.Boolean"/>, a <see cref="System.String"/> or a <see cref="IWebElement"/>. /// An exception will be thrown if the arguments do not meet these criteria. /// The arguments will be made available to the JavaScript via the "arguments" magic /// variable, as if the function were called via "Function.apply" /// </para> /// </remarks> public object ExecuteScript(string script, params object[] args) { IJavaScriptExecutor javascriptDriver = this.driver as IJavaScriptExecutor; if (javascriptDriver == null) { throw new NotSupportedException("Underlying driver instance does not support executing javascript"); } object[] unwrappedArgs = UnwrapElementArguments(args); WebDriverScriptEventArgs e = new WebDriverScriptEventArgs(this.driver, script); this.OnScriptExecuting(e); object scriptResult = javascriptDriver.ExecuteScript(script, unwrappedArgs); this.OnScriptExecuted(e); return scriptResult; }
/// <summary> /// Raises the <see cref="E:OpenQA.Selenium.Support.Events.EventFiringWebDriver.ScriptExecuted"/> event. /// /// </summary> /// <param name="e">A <see cref="T:OpenQA.Selenium.Support.Events.WebDriverScriptEventArgs"/> that contains the event data.</param> protected virtual void OnScriptExecuted(WebDriverScriptEventArgs e) { if (this.ScriptExecuted == null) return; this.ScriptExecuted((object) this, e); }
/// <summary> /// Executes JavaScript asynchronously in the context of the currently selected _frame or window. /// /// </summary> /// <param name="script">The JavaScript code to execute.</param><param name="args">The arguments to the script.</param> /// <returns> /// The value returned by the script. /// </returns> public object ExecuteAsyncScript(string script, params object[] args) { IJavaScriptExecutor javaScriptExecutor = this.driver as IJavaScriptExecutor; if (javaScriptExecutor == null) throw new NotSupportedException("Underlying driver instance does not support executing javascript"); object obj; try { object[] objArray = EventFiringWebDriver.UnwrapElementArguments(args); WebDriverScriptEventArgs e = new WebDriverScriptEventArgs(this.driver, script); this.OnScriptExecuting(e); obj = javaScriptExecutor.ExecuteAsyncScript(script, objArray); this.OnScriptExecuted(e); } catch (Exception ex) { this.OnException(new WebDriverExceptionEventArgs(this.driver, ex)); throw; } return obj; }
/// <summary> /// Raises the <see cref="E:ScriptExecuting" /> event. /// </summary> /// <param name="e">The <see cref="WebDriverScriptEventArgs"/> instance containing the event data.</param> protected override void OnScriptExecuting(WebDriverScriptEventArgs e) { Logger.Trace(CultureInfo.CurrentCulture, "On Script Executing: {0}", e.Script); base.OnScriptExecuting(e); }
/// <summary> /// Executes JavaScript in the context of the currently selected _frame or window. /// </summary> /// <param name="script">The JavaScript code to execute.</param> /// <param name="args">The arguments to the script.</param> /// <returns> /// The value returned by the script. /// </returns> /// <remarks> /// <para> /// The /// <see cref="M:OpenQA.Selenium.Support.Events.EventFiringWebDriver.ExecuteScript(System.String,System.Object[])" /> /// method executes JavaScript in the context of /// the currently selected _frame or window. This means that "document" will refer /// to the current document. If the script has a return value, then the following /// steps will be taken: /// </para> /// <para> /// <list type="bullet"> /// <item> /// <description> /// For an HTML element, this method returns a <see cref="T:OpenQA.Selenium.IWebElement" /> /// </description> /// </item> /// <item> /// <description>For a number, a <see cref="T:System.Int64" /> is returned</description> /// </item> /// <item> /// <description>For a boolean, a <see cref="T:System.Boolean" /> is returned</description> /// </item> /// <item> /// <description>For all other cases a <see cref="T:System.String" /> is returned.</description> /// </item> /// <item> /// <description> /// For an array,we check the first element, and attempt to return a /// <see cref="T:System.Collections.Generic.List`1" /> of that type, following the rules above. Nested /// lists are not /// supported. /// </description> /// </item> /// <item> /// <description> /// If the value is null or there is no return value, /// <see langword="null" /> is returned. /// </description> /// </item> /// </list> /// </para> /// <para> /// Arguments must be a number (which will be converted to a <see cref="T:System.Int64" />), /// a <see cref="T:System.Boolean" />, a <see cref="T:System.String" /> or a /// <see cref="T:OpenQA.Selenium.IWebElement" />. /// An exception will be thrown if the arguments do not meet these criteria. /// The arguments will be made available to the JavaScript via the "arguments" magic /// variable, as if the function were called via "Function.apply" /// </para> /// </remarks> public object ExecuteScript(string script, params object[] args) { var javaScriptExecutor = WrappedDriver as IJavaScriptExecutor; if (javaScriptExecutor == null) throw new NotSupportedException("Underlying driver instance does not support executing javascript"); object obj; try { var objArray = UnwrapElementArguments(args); var e = new WebDriverScriptEventArgs(WrappedDriver, script); OnScriptExecuting(e); obj = javaScriptExecutor.ExecuteScript(script, objArray); OnScriptExecuted(e); } catch (Exception ex) { OnException(new WebDriverExceptionEventArgs(WrappedDriver, ex)); throw; } return obj; }
/// <summary> /// Raises the <see cref="E:OpenQA.Selenium.Support.Events.EventFiringWebDriver.ScriptExecuting" /> event. /// </summary> /// <param name="e"> /// A <see cref="T:OpenQA.Selenium.Support.Events.WebDriverScriptEventArgs" /> that contains the event /// data. /// </param> protected virtual void OnScriptExecuting(WebDriverScriptEventArgs e) { if (ScriptExecuting == null) return; ScriptExecuting(this, e); }
public static void ScriptExecuting(object sender, WebDriverScriptEventArgs e) { //Console.WriteLine("The next script will be executed: " + e.Script); }
private void OnScriptExecuted(object sender, WebDriverScriptEventArgs webDriverScriptEventArgs) { SeleniumLog log = SeleniumLog.Instance(); if (log.Config.OnScriptExecute_LogAfterEvent) { log.Indent(); log.WriteLine("[Selenium Event] Script Executed Successfully!", take_screenshot: log.Config.OnScriptExecute_TakeScreenshotAfterEvent); log.Unindent(); } }
private void OnScriptExecuting(object sender, WebDriverScriptEventArgs webDriverScriptEventArgs) { SeleniumLog log = SeleniumLog.Instance(); if (log.Config.OnScriptExecute_LogBeforeEvent) { log.Indent(); log.WriteLine("[Selenium Event] Script Executing: " + webDriverScriptEventArgs.Script, take_screenshot: log.Config.OnScriptExecute_TakeScreenshotBeforeEvent); log.Unindent(); } }