public void SelectValue(ElementProxy element, string optionValue) { this.Act(CommandType.Action, () => { var unwrappedElement = element.Element as Element; SelectElement selectElement = new SelectElement(unwrappedElement.WebElement); if (selectElement.IsMultiple) { selectElement.DeselectAll(); } selectElement.SelectByValue(optionValue); }); }
public void SelectIndex(ElementProxy element, int optionIndex) { this.Act(CommandType.Action, () => { var unwrappedElement = element.Element as Element; SelectElement selectElement = new SelectElement(unwrappedElement.WebElement); if (selectElement.IsMultiple) { selectElement.DeselectAll(); } selectElement.SelectByIndex(optionIndex); }); }
public ElementProxy FindMultiple(string selector) { var result = new ElementProxy(); this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => { foreach (var element in x.FindMultiple(selector).Elements) { result.Elements.Add(new Tuple <ICommandProvider, Func <IElement> >(x, element.Item2)); } })); return(result); }
private ElementHasTextResult elementHasText(ElementProxy element, Func <string, bool> textMatcher) { var hasText = false; var unwrappedElement = element.Element; var actualText = unwrappedElement.Text; if (unwrappedElement.IsSelect) { foreach (var optionText in unwrappedElement.SelectedOptionTextCollection) { if (textMatcher(optionText)) { hasText = true; break; } } actualText = string.Join(", ", unwrappedElement.SelectedOptionTextCollection.Select(x => x).ToArray()); } else { if (textMatcher(unwrappedElement.Text)) { hasText = true; } } var elementType = "DOM Element"; if (unwrappedElement.IsText) { elementType = "TextElement"; } else if (unwrappedElement.IsMultipleSelect) { elementType = "MultipleSelectElement"; } else if (unwrappedElement.IsSelect) { elementType = "SelectElement"; } return(new ElementHasTextResult { HasText = hasText, ActualText = actualText, ElementType = elementType, Selector = element.Element.Selector }); }
public void NotAttribute(ElementProxy element, string attributeName, string attributeValue) { this.commandProvider.Act(commandType, () => { var result = element.Element.Attributes.Get(attributeName); if (attributeValue == null && result != null) { this.ReportError("Expected element [{0}] not to have attribute [{1}] but it did.", element.Element.Selector, attributeName); } else if (result != null && IsTextMatch(result, attributeValue)) { this.ReportError("Expected element [{0}]'s attribute [{1}] not to have a value of [{2}] but it did.", element.Element.Selector, attributeName, attributeValue); } }); }
public void NotCssProperty(ElementProxy element, string propertyName, string propertyValue) { this.commandProvider.Act(commandType, () => { var result = this.elementHasCssProperty(element, propertyName, propertyValue); if (propertyValue == null && result.HasProperty) { this.ReportError("Expected element [{0}] not to have CSS property [{1}] but it did.", element.Element.Selector, propertyName); } else if (result.PropertyMatches) { this.ReportError("Expected element [{0}]'s CSS property [{1}] not to have a value of [{2}] but it did.", element.Element.Selector, propertyName, propertyValue); } }); }
public void DragAndDrop(ElementProxy source, int sourceOffsetX, int sourceOffsetY, ElementProxy target, int targetOffsetX, int targetOffsetY) { this.Act(CommandType.Action, () => { var element = source.Element as Element; var targetElement = target.Element as Element; new Actions(this.webDriver) .MoveToElement(element.WebElement, sourceOffsetX, sourceOffsetY) .ClickAndHold() .MoveToElement(targetElement.WebElement, targetOffsetX, targetOffsetY) .Release() .Build() .Perform(); }); }
public void CssPropertyValue(ElementProxy element, string propertyName, Action <bool, string> action) { this.Act(CommandType.Action, () => { var propertyValue = ((IJavaScriptExecutor)this.webDriver).ExecuteScript(string.Format("return fluentjQuery(\"{0}\").css(\"{1}\")", element.Element.Selector, propertyName)); if (propertyValue == null) { action(false, string.Empty); } else { action(true, propertyValue.ToString()); } }); }
private int CountElementsInProxy(ElementProxy elements) { int count = 0; foreach (var element in elements.Elements) { try { element.Item2(); count++; } catch (Exception) { } } return(count); }
private ElementHasValueResult elementHasValue(ElementProxy element, Func <string, bool> valueMatcher) { var hasValue = false; var unwrappedElement = element.Element; if (unwrappedElement.IsMultipleSelect) { foreach (var optionValue in unwrappedElement.SelectedOptionValues) { if (valueMatcher(optionValue)) { hasValue = true; break; } } } else { if (valueMatcher(unwrappedElement.Value)) { hasValue = true; } } var elementType = "DOM Element"; if (unwrappedElement.IsText) { elementType = "TextElement"; } else if (unwrappedElement.IsMultipleSelect) { elementType = "MultipleSelectElement"; } else if (unwrappedElement.IsSelect) { elementType = "SelectElement"; } return(new ElementHasValueResult { HasValue = hasValue, ElementType = elementType, ActualValue = unwrappedElement.Value, Selector = element.Element.Selector }); }
public ElementProxy Find(string selector) { var proxy = new ElementProxy(this, () => { try { var webElement = this.webDriver.FindElement(Sizzle.Find(selector)); return(new Element(webElement, selector)); } catch (NoSuchElementException) { throw new FluentElementNotFoundException("Unable to find element with selector [{0}]", selector); } }); return(proxy); }
public void MultiSelectIndex(ElementProxy element, int[] optionIndices) { this.Act(CommandType.Action, () => { var unwrappedElement = element.Element as Element; SelectElement selectElement = new SelectElement(unwrappedElement.WebElement); if (selectElement.IsMultiple) { selectElement.DeselectAll(); } foreach (var optionIndex in optionIndices) { selectElement.SelectByIndex(optionIndex); } }); }
public void MultiSelectText(ElementProxy element, string[] optionTextCollection) { this.Act(CommandType.Action, () => { var unwrappedElement = element.Element as Element; SelectElement selectElement = new SelectElement(unwrappedElement.WebElement); if (selectElement.IsMultiple) { selectElement.DeselectAll(); } foreach (var optionText in optionTextCollection) { selectElement.SelectByText(optionText); } }); }
/// <summary> /// Enter text into specified <paramref name="element"/>. /// </summary> /// <param name="element">IElement factory function.</param> public IActionSyntaxProvider In(ElementProxy element) { if (!element.Element.IsText) { throw new FluentException("Enter().In() is only supported on text elements (input, textarea, etc)."); } if (this.eventsEnabled) { this.syntaxProvider.commandProvider.EnterText(element, text); } else { this.syntaxProvider.commandProvider.EnterTextWithoutEvents(element, text); } return(this.syntaxProvider); }
public void Focus(ElementProxy element) { this.Act(CommandType.Action, () => { var unwrappedElement = element.Element as Element; switch (unwrappedElement.WebElement.TagName) { case "input": case "select": case "textarea": case "a": case "iframe": case "button": var executor = (IJavaScriptExecutor)this.webDriver; executor.ExecuteScript("arguments[0].focus();", unwrappedElement.WebElement); break; } }); }
public void NotValue(ElementProxy element, string value) { this.commandProvider.Act(commandType, () => { var result = elementHasValue(element, (elValue) => IsTextMatch(elValue, value)); if (result.HasValue) { if (element.Element.IsMultipleSelect) { this.ReportError("Expected SelectElement [{0}] selected options to have no options with value of [{1}]. Selected option values include [{2}]", result.Selector, value, string.Join(",", element.Element.SelectedOptionValues)); } else if (element.Element.IsSelect) { this.ReportError("Expected SelectElement [{0}] selected option value not to be [{1}] but it was.", result.Selector, value); } else { this.ReportError("Expected {0} [{1}] value not to be [{2}] but it was.", result.ElementType, result.Selector, value); } } }); }
private ElementHasCssPropertyResult elementHasCssProperty(ElementProxy element, string propertyName, string propertyValue) { var result = new ElementHasCssPropertyResult(); this.commandProvider.CssPropertyValue(element, propertyName, (hasProperty, actualPropertyValue) => { if (!hasProperty) { return; } result.HasProperty = true; result.PropertyValue = actualPropertyValue; if (propertyValue != null && IsTextMatch(actualPropertyValue, propertyValue)) { result.PropertyMatches = true; } }); return(result); }
public void NotText(ElementProxy element, string text) { this.commandProvider.Act(commandType, () => { var result = elementHasText(element, (elText) => IsTextMatch(elText, text)); if (result.HasText) { if (element.Element.IsMultipleSelect) { this.ReportError("Expected SelectElement [{0}] selected options to have no options with text of [{1}]. Selected option text values include [{2}]", result.Selector, text, string.Join(",", element.Element.SelectedOptionTextCollection)); } else if (element.Element.IsSelect) { this.ReportError("Expected SelectElement [{0}] selected option text not to be [{1}] but it was.", result.Selector, text); } else { this.ReportError("Expected {0} [{1}] text not to be [{2}] but it was.", result.ElementType, result.Selector, text); } } }); }
public void NotValue(ElementProxy element, Expression <Func <string, bool> > matchFunc) { this.commandProvider.Act(commandType, () => { var compiledFunc = matchFunc.Compile(); var result = elementHasValue(element, (elValue) => compiledFunc(elValue)); if (result.HasValue) { if (element.Element.IsMultipleSelect) { this.ReportError("Expected SelectElement [{0}] selected options to have no options with value matching expression [{1}]. Selected option values include [{2}]", result.Selector, matchFunc.ToExpressionString(), string.Join(",", element.Element.SelectedOptionValues)); } else if (element.Element.IsSelect) { this.ReportError("Expected SelectElement [{0}] selected option value not to match expression [{1}] but it did.", result.Selector, matchFunc.ToExpressionString()); } else { this.ReportError("Expected {0} [{1}] value not to match expression [{2}] but it did.", result.ElementType, result.Selector, matchFunc.ToExpressionString()); } } }); }
public void Text(ElementProxy element, Expression <Func <string, bool> > matchFunc) { this.commandProvider.Act(commandType, () => { var compiledFunc = matchFunc.Compile(); var result = elementHasText(element, (elText) => compiledFunc(elText)); if (!result.HasText) { if (element.Element.IsMultipleSelect) { this.ReportError("Expected SelectElement [{0}] selected options to have at least one option with text matching expression [{1}]. Selected option text values include [{2}]", result.Selector, matchFunc.ToExpressionString(), string.Join(",", element.Element.SelectedOptionTextCollection)); } else if (element.Element.IsSelect) { this.ReportError("Expected SelectElement [{0}] selected option text to match expression [{1}] but it was actually [{2}].", result.Selector, matchFunc.ToExpressionString(), result.ActualText); } else { this.ReportError("Expected {0} [{1}] text to match expression [{2}] but it was actually [{3}].", result.ElementType, result.Selector, matchFunc.ToExpressionString(), result.ActualText); } } }); }
public ElementProxy FindMultiple(string selector) { var finalResult = new ElementProxy(); finalResult.Children.Add(new Func <ElementProxy>(() => { var result = new ElementProxy(); var webElements = this.webDriver.FindElements(Sizzle.Find(selector)); if (webElements.Count == 0) { throw new FluentElementNotFoundException("Unable to find element with selector [{0}].", selector); } foreach (var element in webElements) { result.Elements.Add(new Tuple <ICommandProvider, Func <IElement> >(this, () => new Element(element, selector))); } return(result); })); return(finalResult); }
public void Visible(ElementProxy element, Action <bool> action) { this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => x.Visible(element, action))); }
public void Focus(ElementProxy element) { this.RepackExceptions(() => Parallel.ForEach(element.Elements, e => e.Item1.Focus(new ElementProxy(e.Item1, e.Item2)))); }
public void Exists(ElementProxy element) { Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).Exists(element)); }
public void NotVisible(ElementProxy element) { Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotVisible(element)); }
public void NotCssProperty(ElementProxy element, string propertyName, string propertyValue) { Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotCssProperty(element, propertyName, propertyValue)); }
public void NotAttribute(ElementProxy element, string attributeName, string attributeValue) { Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotAttribute(element, attributeName, attributeValue)); }
/// <summary> /// Assert the element specified exists. /// </summary> /// <param name="element">Reference to element</param> /// <returns></returns> public AssertSyntaxProvider Exists(ElementProxy element) { this.assertProvider.Exists(element); return(this.assertSyntaxProvider); }
/// <summary> /// Assert that the element is visible and can be interacted with. /// </summary> /// <param name="selector"></param> public AssertSyntaxProvider Visible(ElementProxy element) { this.assertProvider.Visible(element); return(this); }
public void CssPropertyValue(ElementProxy element, string propertyName, Action <bool, string> action) { this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => x.CssPropertyValue(element, propertyName, action))); }