Esempio n. 1
0
        /// <summary>
        /// Assigns the element attributes.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="nativeAttributes">The native attributes.</param>
        protected override void AssignElementAttributes(IWebElement control, ElementLocatorAttribute attribute, object[] nativeAttributes)
        {
            var proxy = control as WebElement;

            if (proxy == null)
            {
                return;
            }

            // Convert any locator property to "find by" classes
            var locators = attribute != null?LocatorBuilder.GetElementLocators(attribute) : new List <By>();

            // Also try to parse the native attributes
            var nativeItems = nativeAttributes != null?nativeAttributes.OfType <FindsByAttribute>().ToList() : null;

            if (nativeItems != null && nativeItems.Count > 0)
            {
                var localLocators = locators;
                locators.AddRange(nativeItems.Where(a => a.Using != null)
                                  .OrderBy(n => n.Priority)
                                  .Select(NativeAttributeBuilder.GetLocator)
                                  .Where(l => l != null && !localLocators.Any(c => Equals(c, l))));
            }

            locators = locators.Count > 1 ? new List <By> {
                new ByChained(locators.ToArray())
            } : locators;
            proxy.UpdateLocators(locators);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the element locator.
        /// </summary>
        /// <returns>The most important locator attribute.</returns>
        protected virtual By GetElementLocator()
        {
            ElementLocatorAttribute attribute;

            return(typeof(TChildElement).TryGetAttribute(out attribute)
                       ? LocatorBuilder.GetElementLocators(attribute).FirstOrDefault()
                       : null);
        }