/// <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) { IWebElement element = this.finder.FindElement(driver, locator); JavaScriptLibrary.ExecuteScript(driver, this.fire, element, this.type); return(null); }
/// <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) { this.alertOverride.ReplaceAlertMethod(); if (this.state.ControlKeyDown || this.state.AltKeyDown || this.state.MetaKeyDown) { throw new SeleniumException("type not supported immediately after call to controlKeyDown() or altKeyDown() or metaKeyDown()"); } string stringToType = this.state.ShiftKeyDown ? value.ToUpperInvariant() : value; IWebElement element = this.finder.FindElement(driver, locator); // TODO(simon): Log a warning that people should be using "attachFile" string tagName = element.TagName; string elementType = element.GetAttribute("type"); if (tagName.ToLowerInvariant() == "input" && elementType != null && elementType.ToLowerInvariant() == "file") { element.SendKeys(stringToType); return(null); } IJavaScriptExecutor executor = driver as IJavaScriptExecutor; if (executor != null) { JavaScriptLibrary.ExecuteScript(driver, this.type, element, stringToType); } else { element.SendKeys(stringToType); } return(null); }
/// <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) { IWebElement one = this.finder.FindElement(driver, locator); IWebElement two = this.finder.FindElement(driver, value); string ordered = " if (arguments[0] === arguments[1]) return false;\n" + "\n" + " var previousSibling;\n" + " while ((previousSibling = arguments[1].previousSibling) != null) {\n" + " if (previousSibling === arguments[0]) {\n" + " return true;\n" + " }\n" + " arguments[1] = previousSibling;\n" + " }\n" + " return false;\n"; bool?result = (bool)JavaScriptLibrary.ExecuteScript(driver, ordered, one, two); return(result != null && result.Value); }
/// <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 tableString = string.Empty; if (!TableParts.IsMatch(locator)) { throw new SeleniumException("Invalid target format. Correct format is tableName.rowNum.columnNum"); } Match tableMatch = TableParts.Match(locator); string tableName = tableMatch.Groups[1].Value; long row = int.Parse(tableMatch.Groups[2].Value, CultureInfo.InvariantCulture); long col = int.Parse(tableMatch.Groups[3].Value, CultureInfo.InvariantCulture); IWebElement table = this.finder.FindElement(driver, tableName); string script = "var table = arguments[0]; var row = arguments[1]; var col = arguments[2];" + "if (row > table.rows.length) { return \"Cannot access row \" + row + \" - table has \" + table.rows.length + \" rows\"; }" + "if (col > table.rows[row].cells.length) { return \"Cannot access column \" + col + \" - table row has \" + table.rows[row].cells.length + \" columns\"; }" + "return table.rows[row].cells[col];"; object returnValue = JavaScriptLibrary.ExecuteScript(driver, script, table, row, col); IWebElement elementReturned = returnValue as IWebElement; if (elementReturned != null) { tableString = elementReturned.Text.Trim(); } else { throw new SeleniumException(returnValue.ToString()); } return(tableString); }
/// <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) { JavaScriptLibrary.ExecuteScript(driver, "arguments[0].id = arguments[1]", this.finder.FindElement(driver, locator), value); return(null); }
/// <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) { IWebElement element = this.finder.FindElement(driver, locator); return(JavaScriptLibrary.ExecuteScript(driver, ElementIndexFinderScript, element)); }
/// <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) { object returnValue = JavaScriptLibrary.ExecuteScript(driver, this.script, locator); return(returnValue is bool && (bool)returnValue); }