public static Element Locate(this IElementsContainer arg, AttributeConstraint findBy)
        {
            Element result = arg.Element(findBy);

            if (result.Exists)
            {
                return(result);
            }

            throw new WatiNException(string.Format("Cannot locate element that matches contraint: {0}", findBy));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs the watin attribute.
        /// </summary>
        /// <param name="FindByAttribute">The find by attribute.</param>
        /// <returns></returns>
        private bool ConstructWatinAttribute(string FindByAttribute)
        {
            if (_ContolStringBuilder.ContainsKey(FindByAttribute))
            {
                string FindByAttributeValue = Convert.ToString(_ContolStringBuilder[FindByAttribute]);

                // If the string starts with .* then build a regex
                if (FindByAttributeValue.StartsWith(".*"))
                {
                    WatinAttribute = Find.By(FindByAttribute, new Regex(FindByAttributeValue));
                }

                    // Assume that it is a string and use string in the attribute
                else
                {
                    if ((FindByAttribute.ToLower() == "url") && FindByAttributeValue.StartsWith(@"http://"))
                    {
                        WatinAttribute = Find.ByUrl(new Uri(FindByAttributeValue));
                    }
                    else if (FindByAttribute.ToLower() == "innertext")
                    {
                        // if the type is custom, we need to split on the : character
                        //string[] splitString = FindByAttributeValue.Split(':');

                        WatinAttribute = Find.By("innertext", FindByAttributeValue);
                    }
                    else
                    {
                        WatinAttribute = Find.By(FindByAttribute, FindByAttributeValue);
                    }
                }
                return true;
            }

            // If we haven't matched an attribute, return false.
            return false;
        }
Ejemplo n.º 3
0
 protected Element Locate(AttributeConstraint constraint)
 {
     return(ie.Locate(constraint));
 }
        public static Element Locate(this Element arg, AttributeConstraint findBy)
        {
            var container = (IElementsContainer)arg;

            return(container.Locate(findBy));
        }