/// <summary> /// Initializes a new instance of the <see cref="Type"/> class. /// </summary> /// <param name="alertOverride">An <see cref="AlertOverride"/> object used to handle JavaScript alerts.</param> /// <param name="elementFinder">An <see cref="ElementFinder"/> used to find the element on which to execute the command.</param> /// <param name="keyState">A <see cref="KeyState"/> object tracking the state of modifier keys.</param> public Type(AlertOverride alertOverride, ElementFinder elementFinder, KeyState keyState) { this.alertOverride = alertOverride; this.finder = elementFinder; this.state = keyState; this.type = "return (" + JavaScriptLibrary.GetSeleniumScript("type.js") + ").apply(null, arguments);"; }
/// <summary> /// Handles the command. /// </summary> /// <param name="driver">The driver used to execute the command.</param> /// <param name="locator">The first parameter to the command.</param> /// <param name="value">The second parameter to the command.</param> /// <returns>The result of the command.</returns> protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string script = JavaScriptLibrary.GetSeleniumScript("isTextPresent.js"); object result = ((IJavaScriptExecutor)driver).ExecuteScript("return (" + script + ")(arguments[0]);", locator); // Handle the null case return(result is bool && (bool)result); }
/// <summary> /// Initializes a new instance of the <see cref="ElementFinder"/> class. /// </summary> public ElementFinder() { string rawScript = JavaScriptLibrary.GetSeleniumScript("findElement.js"); this.findElement = "return (" + rawScript + ")(arguments[0]);"; string linkTextLocator = "return (" + JavaScriptLibrary.GetSeleniumScript("linkLocator.js") + ").call(null, arguments[0], document)"; this.AddStrategy("link", linkTextLocator); }
/// <summary> /// Initializes a new instance of the <see cref="SeleniumSelect"/> class. /// </summary> /// <param name="finder">An <see cref="ElementFinder"/> used in finding options.</param> /// <param name="driver">An <see cref="IWebDriver"/> used to drive the browser.</param> /// <param name="locator">A locator used to find options.</param> public SeleniumSelect(ElementFinder finder, IWebDriver driver, string locator) { this.driver = driver; this.findOption = "return (" + JavaScriptLibrary.GetSeleniumScript("findOption.js") + ").apply(null, arguments)"; this.select = finder.FindElement(driver, locator); if (this.select.TagName.ToLowerInvariant() != "select") { throw new SeleniumException("Element is not a select element: " + locator); } }
/// <summary> /// Initializes a new instance of the <see cref="CompoundMutator"/> class. /// </summary> /// <param name="basePath">The URL to use in mutating the script.</param> public CompoundMutator(string basePath) { this.AddMutator(new VariableDeclaration("selenium", "var selenium = {};")); this.AddMutator(new VariableDeclaration("selenium.browserbot", "selenium.browserbot = {};")); this.AddMutator(new VariableDeclaration("selenium.browserbot.baseUrl", "selenium.browserbot.baseUrl = '" + basePath + "';")); this.AddMutator(new FunctionDeclaration("selenium.page", "if (!selenium.browserbot) { selenium.browserbot = {} }; return selenium.browserbot;")); this.AddMutator(new FunctionDeclaration("selenium.browserbot.getCurrentWindow", "return window;")); this.AddMutator(new FunctionDeclaration("selenium.page().getCurrentWindow", "return window;")); this.AddMutator(new FunctionDeclaration("selenium.browserbot.getDocument", "return document;")); this.AddMutator(new FunctionDeclaration("selenium.page().getDocument", "return document;")); this.AddMutator(new SeleniumMutator("selenium.isElementPresent", JavaScriptLibrary.GetSeleniumScript("isElementPresent.js"))); this.AddMutator(new SeleniumMutator("selenium.isTextPresent", JavaScriptLibrary.GetSeleniumScript("isTextPresent.js"))); this.AddMutator(new SeleniumMutator("selenium.isVisible", JavaScriptLibrary.GetSeleniumScript("isVisible.js"))); this.AddMutator(new SeleniumMutator("selenium.browserbot.findElement", JavaScriptLibrary.GetSeleniumScript("findElement.js"))); }
/// <summary> /// Handles the command. /// </summary> /// <param name="driver">The driver used to execute the command.</param> /// <param name="locator">The first parameter to the command.</param> /// <param name="value">The second parameter to the command.</param> /// <returns>The result of the command.</returns> protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value) { string getText = JavaScriptLibrary.GetSeleniumScript("getText.js"); try { return((string)((IJavaScriptExecutor)driver).ExecuteScript("return (" + getText + ")(arguments[0]);", locator)); } catch (WebDriverException) { // TODO(simon): remove fall back for IE driver IWebElement element = this.finder.FindElement(driver, locator); return(element.Text); } catch (InvalidOperationException) { // TODO(simon): remove fall back for IE driver IWebElement element = this.finder.FindElement(driver, locator); return(element.Text); } }
/// <summary> /// Initializes a new instance of the <see cref="MouseEventAt"/> class. /// </summary> /// <param name="elementFinder">An <see cref="ElementFinder"/> used to find the element on which to execute the command.</param> /// <param name="eventType">The type of event to trigger.</param> public MouseEventAt(ElementFinder elementFinder, string eventType) { this.finder = elementFinder; this.type = eventType; this.fire = "return (" + JavaScriptLibrary.GetSeleniumScript("fireEventAt.js") + ").apply(null, arguments);"; }
/// <summary> /// Initializes a new instance of the <see cref="FireEvent"/> class. /// </summary> /// <param name="elementFinder">An <see cref="ElementFinder"/> used to find the element on which to execute the command.</param> public FireEvent(ElementFinder elementFinder) { this.finder = elementFinder; this.fire = "return (" + JavaScriptLibrary.GetSeleniumScript("fireEvent.js") + ").apply(null, arguments);"; }
/// <summary> /// Initializes a new instance of the <see cref="FireNamedEvent"/> class. /// </summary> /// <param name="elementFinder">An <see cref="ElementFinder"/> used to find the element on which to execute the command.</param> /// <param name="eventName">The name of the event to fire.</param> public FireNamedEvent(ElementFinder elementFinder, string eventName) { this.finder = elementFinder; this.name = eventName; this.fire = "return (" + JavaScriptLibrary.GetSeleniumScript("fireEvent.js") + ").apply(null, arguments);"; }
/// <summary> /// Initializes a new instance of the <see cref="IsSomethingSelected"/> class. /// </summary> public IsSomethingSelected() { this.script = "return (" + JavaScriptLibrary.GetSeleniumScript("isSomethingSelected.js") + ").apply(null, arguments)"; }