public void EnterData(ISearchContext context, IWebElement element, object data) { var options = findOptions(element); foreach (var option in options) { if (option.Text == data.ToString()) { option.Click(); return; } } foreach (var option in options) { if (option.GetAttribute("value") == data.ToString()) { option.Click(); return; } } var message = "Cannot find the desired option\nThe available options are\nDisplay/Key\n"; foreach (var option in options) { message += "\n" + "{0}/{1}".ToFormat(option.Text, option.GetAttribute("value")); } StoryTellerAssert.Fail(message); }
/// <summary> /// Finds many elements /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>A readonly collection of elements that match.</returns> public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { if (this.bys.Length == 0) { return new List<IWebElement>().AsReadOnly(); } List<IWebElement> elems = null; foreach (By by in this.bys) { List<IWebElement> newElems = new List<IWebElement>(); if (elems == null) { newElems.AddRange(by.FindElements(context)); } else { foreach (IWebElement elem in elems) { newElems.AddRange(elem.FindElements(by)); } } elems = newElems; } return elems.AsReadOnly(); }
/// <summary> /// Locates an element using the given <see cref="ISearchContext"/> and list of <see cref="By"/> criteria. /// </summary> /// <param name="searchContext">The <see cref="ISearchContext"/> object within which to search for an element.</param> /// <param name="bys">The list of methods by which to search for the element.</param> /// <returns>An <see cref="IWebElement"/> which is the first match under the desired criteria.</returns> public IWebElement LocateElement(ISearchContext searchContext, IEnumerable<By> bys) { if (searchContext == null) { throw new ArgumentNullException("searchContext", "searchContext may not be null"); } if (bys == null) { throw new ArgumentNullException("bys", "List of criteria may not be null"); } string errorString = null; foreach (var by in bys) { try { return searchContext.FindElement(by); } catch (NoSuchElementException) { errorString = (errorString == null ? "Could not find element by: " : errorString + ", or: ") + by; } } throw new NoSuchElementException(errorString); }
/// <summary> /// Finds many elements /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>A readonly collection of elements that match.</returns> public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { if (this.bys.Length == 0) { return new List<IWebElement>().AsReadOnly(); } IEnumerable<IWebElement> elements = null; foreach (By by in this.bys) { ReadOnlyCollection<IWebElement> foundElements = by.FindElements(context); if (foundElements.Count == 0) { // Optimization: If at any time a find returns no elements, the // only possible result for find-all is an empty collection. return new List<IWebElement>().AsReadOnly(); } if (elements == null) { elements = foundElements; } else { elements = elements.Intersect(by.FindElements(context)); } } return elements.ToList().AsReadOnly(); }
/// <summary> /// Initializes a new instance of the <see cref="WebElement" /> class. /// </summary> /// <param name="searchContext">The driver used to search for elements.</param> protected internal WebElement(ISearchContext searchContext) { this.searchContext = searchContext; this.bys = new List<By>(); this.Cache = true; }
public static void AssertElementPresent(ISearchContext context, By searchBy, string elementDescription) { if (!IsElementPresent(context, searchBy)) { throw new AssertionException(String.Format("AssertElementPresent Failed: Could not find '{0}'", elementDescription)); } }
public static IEnumerable<By> CreateBys(ISearchContext context, MemberInfo member) { string platform = GetPlatform(context); string automation = GetAutomation(context); IEnumerable<By> defaultBys = CreateDefaultLocatorList(member); ReadOnlyCollection<By> defaultByList = new List<By>(defaultBys).AsReadOnly(); IEnumerable<By> nativeBys = CreateNativeContextLocatorList(member, platform, automation); IList<By> nativeByList = null; if (nativeBys == null) nativeByList = defaultByList; else nativeByList = new List<By>(nativeBys).AsReadOnly(); Dictionary<ContentTypes, IEnumerable<By>> map = new Dictionary<ContentTypes, IEnumerable<By>>(); map.Add(ContentTypes.HTML, defaultByList); map.Add(ContentTypes.NATIVE, nativeByList); ContentMappedBy by = new ContentMappedBy(map); List<By> bys = new List<By>(); bys.Add(by); return bys.AsReadOnly(); }
public static IWebElement FindTextbox(ISearchContext context, IWebElement element) { var id = element.GetAttribute("id"); var labelId = id + "Value"; return context.FindElement(By.Id(labelId)); }
public void SetUp() { mocks = new Mockery(); mockDriver = mocks.NewMock<ISearchContext>(); mockElement = mocks.NewMock<IWebElement>(); mockExplicitDriver = mocks.NewMock<IWebDriver>(); }
/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public IEnumerable<SearchResult> Execute(ISearchContext context) { using (var session = this._dbFunction.CreateSession()) { return session.GetTyped<SearchResult>(r => r.executesearch(context)); } }
/// <summary> /// Initializes a new instance of the <see cref="WebElementProxy"/> class. /// </summary> /// <param name="searchContext">The driver used to search for elements.</param> /// <param name="bys">The list of methods by which to search for the element.</param> /// <param name="cache"><see langword="true"/> to cache the lookup to the element; otherwise, <see langword="false"/>.</param> /// <param name="locatorFactory">The <see cref="IElementLocatorFactory"/> implementation that /// determines how elements are located.</param> internal WebElementProxy(ISearchContext searchContext, IEnumerable<By> bys, bool cache, IElementLocatorFactory locatorFactory) { this.locatorFactory = locatorFactory; this.searchContext = searchContext; this.bys = bys; this.cache = cache; }
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { // Create script arguments object[] scriptArgs = new object[this.args.Length + 1]; scriptArgs[0] = this.RootElement; Array.Copy(this.args, 0, scriptArgs, 1, this.args.Length); // Get JS executor IJavaScriptExecutor jsExecutor = context as IJavaScriptExecutor; if (jsExecutor == null) { IWrapsDriver wrapsDriver = context as IWrapsDriver; if (wrapsDriver != null) { jsExecutor = wrapsDriver.WrappedDriver as IJavaScriptExecutor; } } if (jsExecutor == null) { throw new NotSupportedException("Could not get an IJavaScriptExecutor instance from the context."); } ReadOnlyCollection<IWebElement> elements = jsExecutor.ExecuteScript(this.script, scriptArgs) as ReadOnlyCollection<IWebElement>; if (elements == null) { elements = new ReadOnlyCollection<IWebElement>(new List<IWebElement>(0)); } return elements; }
public TestSearchContext(TestSettings settings, By selfSelector, ISearchContext context,Func<IWebElement> selfLookup) { _settings = settings; _selfSelector = selfSelector; _context = context; _selfLookup = selfLookup; }
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { var scriptExecutor = DriverWrapperUnwrapper.GetDriverImplementationOf<IJavaScriptExecutor>(context); EnsureScriptIsLoaded(scriptExecutor); IEnumerable<object> scriptResult = null; object executeScript; if (context is IWebElement) { executeScript = scriptExecutor.ExecuteScript("return " + resultPrefix + javascriptGlobal + "(" + selector + ", arguments[0])" + resultPosftix, context); } else { executeScript = scriptExecutor.ExecuteScript("return " + resultPrefix + javascriptGlobal + "(" + selector + ")" + resultPosftix); } scriptResult = (IEnumerable<object>)executeScript; var result = new ReadOnlyCollection<IWebElement>(scriptResult.Cast<IWebElement>().ToList()); return result; }
public RelatedOppsSections(ISearchContext context) : base(context) { Element("Title", By.CssSelector(".contact-opportunity__name")); Element("Stage", By.CssSelector(".contact-opportunity .contact-opportunity__status:nth-of-type(1)")); Element("Value", By.CssSelector(".contact-opportunity .contact-opportunity__status:nth-of-type(2)")); }
public string GetData(ISearchContext context, IWebElement element) { // TODO: discuss how to fix in a more elegant manner. ISearchContext reference is null here // so we use the one we hijacked from EnterData IWebElement textbox = FindTextbox(_searchContext, element); return new TextboxElementHandler().GetData(_searchContext, textbox); }
public virtual void EraseData(ISearchContext context, IWebElement element) { if (element.GetAttribute("value").IsNotEmpty()) { element.Click(); element.SendKeys(Keys.Home + Keys.Shift + Keys.End + Keys.Backspace); } }
/// <summary> /// Finds many elements /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>A readonly collection of elements that match.</returns> public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { List<IWebElement> elements = new List<IWebElement>(); elements.AddRange(this.idFinder.FindElements(context)); elements.AddRange(this.nameFinder.FindElements(context)); return elements.AsReadOnly(); }
/// <summary> /// Find a single element. /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>The element that matches</returns> public override IWebElement FindElement(ISearchContext context) { var tmpContext = context as IFindByIosUIAutomation; if (null == tmpContext) { throw new InvalidCastException(_UnableToCast); } return tmpContext.FindElementByIosUIAutomation(_Selector); }
/// <summary> /// Creates an <see cref="IElementLocator"/> object used to locate elements. /// </summary> /// <param name="searchContext">The <see cref="ISearchContext"/> object that the /// locator uses for locating elements.</param> /// <returns>The <see cref="IElementLocator"/> used to locate elements.</returns> public IElementLocator CreateLocator(ISearchContext searchContext) { if (searchContext == null) { throw new ArgumentNullException("searchContext", "searchContext may not be null"); } return new RetryingElementLocator(searchContext, this.timeout, this.pollingInterval); }
/// <summary> /// Finds many elements /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>A readonly collection of elements that match.</returns> public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { var tmpContext = context as IFindByAndroidUIAutomator; if (null == tmpContext) { throw new InvalidCastException(_UnableToCastError); } return tmpContext.FindElementsByAndroidUIAutomator(_Selector); }
public void EnterData(ISearchContext context, IWebElement element, object data) { if (element.Text.IsNotEmpty() || element.GetAttribute("value").IsNotEmpty()) { element.Clear(); } element.SendKeys(data as string ?? string.Empty); }
public void Init() { this.context = MockRepository.GenerateStub<ISearchContext>(); this.element1 = MockRepository.GenerateStub<IWebElement>(); this.element2 = MockRepository.GenerateStub<IWebElement>(); this.element1.Stub(x => x.GetAttribute("id")).Return("e1"); this.element2.Stub(x => x.GetAttribute("id")).Return("e2"); }
/// <summary> /// Initializes the elements in the Page Object. /// </summary> /// <param name="driver">The driver used to find elements on the page.</param> /// <param name="page">The Page Object to be populated with elements.</param> public static void InitElements(ISearchContext driver, object page) { const BindingFlags BindingOptions = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy; if (page == null) { throw new ArgumentNullException("page", "page cannot be null"); } var type = page.GetType(); var fields = type.GetFields(BindingOptions); var properties = type.GetProperties(BindingOptions); var members = new List<MemberInfo>(fields); members.AddRange(properties); foreach (var member in members) { var attributes = member.GetCustomAttributes(typeof(FindsByAttribute), true); foreach (var attribute in attributes) { var castedAttribute = (FindsByAttribute)attribute; var generator = new ProxyGenerator(); var cacheAttributeType = typeof(CacheLookupAttribute); var cache = member.GetCustomAttributes(cacheAttributeType, true).Length != 0 || member.DeclaringType.GetCustomAttributes(cacheAttributeType, true).Length != 0; var interceptor = new ProxiedWebElementInterceptor(driver, castedAttribute.Bys, cache); var options = new ProxyGenerationOptions { BaseTypeForInterfaceProxy = typeof(WebElementProxyComparer) }; var field = member as FieldInfo; var property = member as PropertyInfo; if (field != null) { var proxyElement = generator.CreateInterfaceProxyWithoutTarget( typeof(IWrapsElement), new[] { field.FieldType }, options, interceptor); field.SetValue(page, proxyElement); } else if (property != null) { var proxyElement = generator.CreateInterfaceProxyWithoutTarget( typeof(IWrapsElement), new[] { property.PropertyType }, options, interceptor); property.SetValue(page, proxyElement, null); } } } }
/// <summary> /// Creates an <see cref="IElementLocator"/> object used to locate elements. /// </summary> /// <param name="searchContext">The <see cref="ISearchContext"/> object that the /// locator uses for locating elements.</param> /// <returns>The <see cref="IElementLocator"/> used to locate elements.</returns> public IElementLocator CreateLocator(ISearchContext searchContext) { if (searchContext == null) { throw new ArgumentNullException("searchContext", "searchContext may not be null"); } return new DefaultElementLocator(searchContext); }
public string GetData(ISearchContext context, IWebElement element) { var selected = findSelected(element); if (selected == null) return "Nothing"; var value = selected.GetAttribute("value"); return value.IsEmpty() ? selected.Text : "{0}={1}".ToFormat(selected.Text, value); }
public void EnterData(ISearchContext context, IWebElement element, object data) { while (element.GetAttribute("value").IsNotEmpty()) { element.SendKeys(Keys.Backspace); } element.SendKeys(data as string ?? string.Empty); }
/// <summary> /// Finds many elements /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>A readonly collection of elements that match.</returns> public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context) { var tmpContext = context as IFindByAccessibilityId; if (null == tmpContext) { throw new InvalidCastException("Unable to cast ISearchContext to IFindByAccessibilityId"); } return tmpContext.FindElementsByAccessibilityId(selector); }
/// <summary> /// Find a single element. /// </summary> /// <param name="context">Context used to find the element.</param> /// <returns>The element that matches</returns> public override IWebElement FindElement(ISearchContext context) { ReadOnlyCollection<IWebElement> elements = this.FindElements(context); if (elements.Count == 0) { throw new NoSuchElementException("Cannot locate an element using " + this.ToString()); } return elements[0]; }
public static bool IsElementPresent(ISearchContext context, By searchBy) { try { var b = context.FindElement(searchBy).Displayed; return true; } catch { return false; } }
public HtmlElementLocatorFactory(ISearchContext searchContext) { this.searchContext = searchContext; }
public void SetUp() { mocks = new Mockery(); mockDriver = mocks.NewMock <ISearchContext>(); mockElement = mocks.NewMock <IWebElement>(); }
public static ReadOnlyCollection <IWebElement> FindElements(this IWebDriver driver, ISearchContext searchContext, By by, int timeoutInSeconds = 10) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds)); return(wait.Until(drv => (searchContext.FindElements(by).Count > 0) ? searchContext.FindElements(by) : null)); }
public QualificationSummaryItem(ISearchContext parent) : base(parent) { }
public override ReadOnlyCollection <IWebElement> FindElements(ISearchContext context) { return(new ReadOnlyCollection <IWebElement>(_function(context).ToList())); }
public static IWebElement LabelFor <T>(this ISearchContext context, Expression <Func <T, object> > property) { return(context.FindElement(By.CssSelector("label[for='{0}']".ToFormat(property.ToAccessor().Name)))); }
public static void SetData(this ISearchContext context, IWebElement element, string value) { ElementHandlers.FindHandler(element).EnterData(context, element, value); }
IReadOnlyCollection <IWebElement> IFind.Find(ISearchContext context, string searchText) { return(context.FindElements(By.XPath(searchText))); }
/// <summary> /// Do a wait until check where we are checking text equals value of attribute given /// </summary> /// <param name="by">'by' selector for the element</param> /// <param name="textValue">String value that the element's attribute is expected to equal</param> /// <param name="attribute">Attribute name as a String</param> /// <param name="searchContext">Search context - either web driver or web element</param> /// <returns>Element if the check passed</returns> private static Func <IWebDriver, IWebElement> AttributeEqualsExpectedText(By by, string textValue, string attribute, ISearchContext searchContext) { return(driver => { var element = searchContext.FindElement(by); var elementValue = element.GetAttribute(attribute); return (elementValue != null && elementValue.Equals(textValue)) ? element : null; }); }
public override IWebElement FindElement(ISearchContext context) { return(context.FindElement(XPath(".//*[{0}]".FormatString(BuildAttributeSelector())))); }
public override ReadOnlyCollection <IWebElement> FindElements(ISearchContext context) { return(context.FindElements(XPath(".//*[{0}]".FormatString(BuildAttributeSelector())))); }
/// <summary> /// Check if an element contains the expected text - Case insensitive /// </summary> /// <param name="by">'by' selector for the element</param> /// <param name="text">The expected text</param> /// <param name="searchContext">Search context - either web driver or web element</param> /// <returns>Success if the element contains the expected text</returns> private static Func <IWebDriver, IWebElement> ElementContainsExpectedText(By by, string text, ISearchContext searchContext) { return(driver => { var element = searchContext.FindElement(by); return (element != null && element.Displayed && element.Text.ToUpper().Contains(text.ToUpper())) ? element : null; }); }
public SpoilerCaption(ISearchContext searchContext, By @by) : base(searchContext, @by) { }
public SettingsPage(ISearchContext context) : base(context) { }
public static IWebElement InputFor <T>(this ISearchContext context, Expression <Func <T, object> > property) { return(context.FindElement(By.Name(property.ToAccessor().Name))); }
public InventoryItem(IWebDriver driver, ISearchContext context) : base(driver, context) { }
public static string GetData(this ISearchContext context, IWebElement element) { return(ElementHandlers.FindHandler(element).GetData(context, element)); }
public CalculateNumberOfItemsToShowStepUnitTests() { _context = new SearchContext(new FindViewModel()); _searchStep = new CalculateNumberOfItemsToShowStep(); }
public bool AnyFiltersActive(ISearchContext searchContext) { return(selectedFilterProviders.Any(selectedFilterProvider => selectedFilterProvider.AnyFacetsActive(searchContext))); }
/// <summary> /// Initializes a new instance of the <see cref="Wait"/> class. /// </summary> /// <param name="searchItem">The search context item</param> /// <param name="webDriverWait">The wait driver</param> internal Wait(ISearchContext searchItem, WebDriverWait webDriverWait) { this.searchItem = searchItem; this.webDriverWait = webDriverWait; }
public FacetSearchQuery(ISearchContext searchContext, string category, Analyzer analyzer, string[] fields, LuceneSearchOptions searchOptions, BooleanOperation occurance) : base(searchContext, category, analyzer, fields, searchOptions, occurance) { }
public static IWebElement FinElementAndInput(this ISearchContext ISearch, IWebDriver webDriver, By by, string str = "", Func <string> GetInputStr = null) { Size size; IWebElement webElement; int? nullable; int? nullable1; int? nullable2; dynamic py = null; IWebElement el = null; try { el = ISearch.FindElement(by); el.Clear(); Thread.Sleep(300); if (GetInputStr != null) { str = GetInputStr(); } Actions actionChains = new Actions(webDriver); Random random = HelperGeneral.Random; size = el.Size; int num = random.Next(3, size.Width); Random random1 = HelperGeneral.Random; size = el.Size; py = new { X = num, Y = random1.Next(3, size.Height) }; actionChains.MoveToElement(el, py.X, py.Y).Click().SendKeys(str).Perform(); Thread.Sleep(2000); webElement = el; return(webElement); } catch (Exception exception) { Exception ex = exception; object[] objArray = new object[] { by.ToString(), ex.Message, null, null, null, null }; dynamic obj = py; objArray[2] = (obj != null ? obj.X : null); obj = py; objArray[3] = (obj != null ? obj.Y : null); if (el != null) { size = el.Size; nullable1 = new int?(size.Width); } else { nullable = null; nullable1 = nullable; } objArray[4] = nullable1; if (el != null) { size = el.Size; nullable2 = new int?(size.Height); } else { nullable = null; nullable2 = nullable; } objArray[5] = nullable2; XTrace.WriteLine(string.Format("FinElementAndInput {0} {1} 点击偏移{2},{3} 元素大小{4},{5}", objArray)); } webElement = null; return(webElement); }
private static CustomMultiFieldQueryParser CreateQueryParser(ISearchContext searchContext, string[] fields, Analyzer analyzer) => new ExamineMultiFieldQueryParser(searchContext, LuceneVersion, fields, analyzer);
/// <summary> /// Initializes a new instance of the <see cref="HomePage" /> class by using the provided parent control. /// </summary> /// <param name="context">The <see cref="ISearchContext" /> that contains this control.</param> public ApprenticeshipVacancyNotFound(ISearchContext context) { }
public MyElement(IWebElement element, By by, ISearchContext search) { _search = search; _element = element; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultElementLocator"/> class. /// </summary> /// <param name="searchContext">The <see cref="ISearchContext"/> used by this locator /// to locate elements.</param> public DefaultElementLocator(ISearchContext searchContext) { this.SearchContext = searchContext; }
ShadowRoot GetShadowRoot(ISearchContext element) { var result = ((IJavaScriptExecutor)Browser).ExecuteScript("return arguments[0].shadowRoot", element); return((ShadowRoot)result); }
public ElementsFinder(By locator, string name, ISearchContext context) : base(name) { _locator = locator; _context = context; }
/// <summary> /// Custom extension: /// Finds the first IWebElement given the search parameters, null if not found /// </summary> public static IWebElement FindElementNull(this ISearchContext context, By by) { var elements = context.FindElements(by); return(elements.Any() ? elements[0] : null); }
/// <summary> /// Finds the first element matching the criteria. /// </summary> /// <param name="context">An <see cref="T:OpenQA.Selenium.ISearchContext"/> object to use to search for the elements.</param> /// <returns> /// The first matching <see cref="T:OpenQA.Selenium.IWebElement"/> on the current context. /// </returns> public override IWebElement FindElement(ISearchContext context) { return(FindElements(context).First()); }