Exemplo n.º 1
0
        static public ElementCollection GetElementsByXPath(this IElementContainer container, string xpath)
        {
            DateTime now = DateTime.Now;

            xpath = xpath.Trim();
            if (xpath[xpath.Length - 1] == '/')
            {
                xpath = xpath.Substring(0, xpath.Length - 1);
            }
            var constraint = ActionElementBase.GetConstraint(new FindAttribute()
            {
                FindMethod = FindMethods.XPath,
                FindValue  = xpath,
                Regex      = true,
            });
            string tagName = GetLastTag(xpath);

            int index = xpath.IndexOf("*");
            ElementCollection elements = null;

            if (index > 0)
            {
                elements = GetElementsByXPath(container, xpath.Substring(0, xpath.Substring(0, index).LastIndexOf("/")));

                if (elements.Count > 0)
                {
                    return(GetElementsByTag((IElementContainer)elements[0], tagName, constraint));
                }
                return(null);
            }

            elements = GetElementsByTag(container, tagName, constraint);
            logger.Info("GetElementsByXPath:" + DateTime.Now.Subtract(now).TotalMilliseconds);
            return(elements);
        }
Exemplo n.º 2
0
 public Constraint FindByAttr(string attr, string value)
 {
     return(ActionElementBase.GetConstraint(new FindAttribute()
     {
         FindMethod = (FindMethods)Enum.Parse(typeof(FindMethods), attr, true),
         FindValue = value,
         Regex = true,
     }));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取同一个元素的活动项
        /// </summary>
        /// <param name="constraint"></param>
        /// <returns></returns>
        public List <ActionElementBase> GetTheElementActions(WatiN.Core.Constraints.Constraint constraint)
        {
            string cs = constraint.ToString();
            List <ActionElementBase> aes = new List <ActionElementBase>();

            foreach (var o in this)
            {
                ActionElementBase ae = o as ActionElementBase;
                if (ae == null)
                {
                    continue;
                }
                if (ae.GetConstraint().ToString() == cs)
                {
                    aes.Add(ae);
                }
            }
            return(aes);
        }
Exemplo n.º 4
0
        private int FindClickAction(ActionElementBase ab)
        {
            int index = -1;

            for (int i = 0; i < this.Count; i++)
            {
                ActionElementBase action = this[i] as ActionElementBase;
                if (action == null)
                {
                    continue;
                }
                if ((action is ActionClick) && action.GetConstraint().ToString() == ab.GetConstraint().ToString())
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 为活动选择元素增加标签说明
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void view_TagLabelEvent(object sender, EventArgs e)
        {
            ICoreBrowser browser       = Context.Browser;
            IHTMLElement activeElement = null;

            if (browser.Selector != null && browser.Selector.SelectorElement != null)
            {
                activeElement = browser.Selector.SelectorElement;
            }
            if (activeElement == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(activeElement.innerText))
            {
                return;
            }

            //int selectIndex = Context.State.SelectItemIndex;
            //if (selectIndex == -1) return;
            ActionBase actionBase = Context.State.ActiveAction;//wsv.DataSource[wsv.SelectItemIndex - 1] as ActionBase;

            if (actionBase == null)
            {
                return;
            }
            ActionElementBase ae = actionBase as ActionElementBase;

            if (ae == null)
            {
                return;
            }

            List <ActionElementBase> aes = Model.ActiveActionModel.GetTheElementActions(ae.GetConstraint());
            string labelText             = activeElement.innerText.Replace(":", "").Replace(":", "").Trim();

            foreach (var o in aes)
            {
                o.Title = labelText;
            }
            // wsv.DataBind();
        }