public async Task <object> ExecuteScript(string script, string filename = null, string sandbox = "defaultSandbox", CancellationToken cancellationToken = new CancellationToken(), params object[] args) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new ExecuteScriptCommand(script) { filename = filename, sandbox = sandbox }; if (args.Length > 0) { comm1.Args = args; //.Select(v => v.ToString()).ToArray(); } await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { var err = comm1.Error["error"]?.ToString(); if (err == "javascript error") { throw new InvalidOperationException(comm1.Error["message"].ToString() ?? comm1.Error.ToString()); } /*if (err == "stale element reference") */ throw new WebBrowserException(comm1.Error); } return(ParseExecuteScriptReturnValue((comm1.Result as JObject)?["value"])); //comm1.Result; }
public async Task PressKey(string keyToPress, CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); var el = await asyncFirefoxDriver.TargetLocator.SwitchToActiveElement(cancellationToken).ConfigureAwait(false); await asyncFirefoxDriver.Elements.SendKeysToElement(el, keyToPress).ConfigureAwait(false); }
public async Task Back(CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new GoBackCommand(); await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { throw new WebBrowserException(comm1.Error); } }
public async Task <string> Text(CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new GetTextFromDialogCommand(); await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { throw new WebBrowserException(comm1.Error); } return(comm1.Result is JValue?comm1.Result.ToString() : comm1.Result?["value"]?.ToString()); }
public async Task <WebPoint> GetPosition(CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new GetWindowPositionCommand(); await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { throw new WebBrowserException(comm1.Error); } return(ResultValueConverter.ToWebPoint(comm1.Result)); }
private async Task <TimeSpan> GetTimeout(string timeoutType, CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new GetTimeoutsCommand(); await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { throw new WebBrowserException(comm1.Error); } var res = comm1.Result?[timeoutType]?.ToString(); if (res == null) { throw new WebBrowserException("Specified timeout type not defined"); } return(TimeSpan.FromMilliseconds(Convert.ToDouble(res, CultureInfo.InvariantCulture))); }
public async Task <Screenshot> TakeScreenshot(string elementId, string highlights, string full, string hash, CancellationToken cancellationToken = new CancellationToken()) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new TakeScreenshotCommand(elementId, highlights, full, hash); await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { throw new WebBrowserException(comm1.Error); } return(new Screenshot((string)comm1.Result?["value"])); }
public async Task Click(ICoordinates where, CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); throw new NotImplementedException(); }