/// <summary> /// Waits for an file input element to appear and uploads a file to it. /// Internally calls Wait. /// </summary> /// <param name="actor">The Screenplay Actor.</param> /// <param name="driver">The WebDriver.</param> public override void PerformAs(IActor actor, IWebDriver driver) { actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); var element = driver.FindElement(Locator.Query); element.SendKeys(FilePath); }
/// <summary> /// Gets the list of the Web element's CSS classes. /// </summary> /// <param name="actor">The Screenplay Actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override string[] RequestAs(IActor actor, IWebDriver driver) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); string classes = driver.FindElement(Locator.Query).GetAttribute("class"); return(classes == null?Array.Empty <string>() : classes.Split()); }
/// <summary> /// Gets a web element's JavaScript textContent value. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override TValue RequestAs(IActor actor, IWebDriver driver) { object[] newArgs = Args; // If a locator is given, get the element and make it the first argument if (Locator != null) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); var e = driver.FindElement(Locator.Query); IList <object> tempList = Args.ToList(); tempList.Insert(0, e); newArgs = tempList.ToArray(); } // Log the script actor.Logger.Info("JavaScript code to execute:"); actor.Logger.Info(Script); // Log the arguments if (newArgs != null && newArgs.Length > 0) { actor.Logger.Info("JavaScript code arguments:"); foreach (var a in newArgs) { actor.Logger.Info(a.ToString()); } } // Execute the script object response = ((IJavaScriptExecutor)driver).ExecuteScript(Script, newArgs); // Return the type-casted result return((TValue)response); }
/// <summary> /// Gets the list of the Web element's CSS classes. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override string[] RequestAs(IActor actor, IWebDriver driver) { actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); string classes = driver.FindElement(Locator.Query).GetAttribute("class"); return(classes.Split()); }
/// <summary> /// Finds all Web elements on the page matching the provided locator and gets a value from each. /// </summary> /// <param name="actor">The Screenplay Actor.</param> /// <param name="driver">The Selenium web driver.</param> /// <param name="locator">Locator used to find Web elements.</param> /// <param name="getValue">The method used to obtain the desired value from each Web element.</param> /// <returns>A list of string values from each Web element found.</returns> public static IEnumerable <string> GetValues(IActor actor, IWebDriver driver, IWebLocator locator, Func <IWebElement, string> getValue) { actor.WaitsUntil(Existence.Of(locator), IsEqualTo.True()); var elements = driver.FindElements(locator.Query); var strings = from e in elements select getValue(e); // ToList() will avoid lazy evaluation return(strings.ToList()); }
/// <summary> /// Gets the Web element's text. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override IEnumerable <string> RequestAs(IActor actor, IWebDriver driver) { actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); var elements = driver.FindElements(Locator.Query); var strings = from e in elements select e.Text; // ToList() will avoid lazy evaluation return(strings.ToList()); }
/// <summary> /// Makes a direct call to a JavaScript element and returns the result. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override TValue RequestAs(IActor actor, IWebDriver driver) { actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); var e = driver.FindElement(Locator.Query); var newList = Args.ToList(); newList.Insert(0, e); return((TValue)((IJavaScriptExecutor)driver).ExecuteScript(Script, newList.ToArray())); }
/// <summary> /// Selects an option by text in a select element. /// </summary> /// <param name="actor">The screenplay actor.</param> /// <param name="driver">The WebDriver.</param> public override void PerformAs(IActor actor, IWebDriver driver) { actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); var select = new SelectElement(driver.FindElement(Locator.Query)); if (Index != null) { select.SelectByIndex((int)Index); } else if (Text != null) { select.SelectByText(Text, PartialMatch); } else if (Value != null) { select.SelectByValue(Value); } else { throw new BrowserInteractionException( $"No select method (index, text, or value) provided for Select task"); } }
/// <summary> /// Returns true if the element is enabled on the page; false otherwise. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override bool RequestAs(IActor actor, IWebDriver driver) { actor.AttemptsTo(Wait.Until(Existence.Of(Locator), IsEqualTo.True())); return(driver.FindElement(Locator.Query).Enabled); }
/// <summary> /// Gets the text of a select Web element's selected option. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override IList <string> RequestAs(IActor actor, IWebDriver driver) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); return(new SelectElement(driver.FindElement(Locator.Query)).Options.Select(o => o.Text).ToList()); }
/// <summary> /// Returns true if the element is selected; otherwise false. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override bool RequestAs(IActor actor, IWebDriver driver) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); return(driver.FindElement(Locator.Query).Selected); }
/// <summary> /// Gets the text of a select Web element's selected option. /// </summary> /// <param name="actor">The Screenplay Actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override string RequestAs(IActor actor, IWebDriver driver) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); return(new SelectElement(driver.FindElement(Locator.Query)).SelectedOption.Text); }
/// <summary> /// Gets a web element's HTML attribute by name. /// </summary> /// <param name="actor">The actor.</param> /// <param name="driver">The WebDriver.</param> /// <returns></returns> public override string RequestAs(IActor actor, IWebDriver driver) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); return(driver.FindElement(Locator.Query).GetAttribute(PropertyName)); }
/// <summary> /// Submits a form. /// Submit may be called on any element in the form. /// This may be more convenient than explicitly searching for the form's submit input. /// </summary> /// <param name="actor">The Screenplay Actor.</param> /// <param name="driver">The WebDriver.</param> public override void PerformAs(IActor actor, IWebDriver driver) { actor.WaitsUntil(Existence.Of(Locator), IsEqualTo.True()); driver.FindElement(Locator.Query).Submit(); }