Exemple #1
0
        /// <summary>
        /// id或className需要分大小写
        /// </summary>
        /// <param name="element"></param>
        /// <param name="fullPath"></param>
        /// <param name="ignoreSelectArea">是否检查选择区域</param>
        /// <returns></returns>
        private string GetCssPath(mshtml.IHTMLElement element, bool fullPath, bool ignoreSelectArea)
        {
            if (element == null)
            {
                return("");
            }

            if (SelectAreaSelector != null && !ignoreSelectArea)
            {
                if (!element.IsChildOf(SelectAreaSelector))
                {
                    throw new ApplicationException("必须在选择区域内定位元素,定位元素失败!");
                }
                string childCssSelector = GetContextSelector(SelectAreaSelector, element);
                return(GetCssPath(SelectAreaSelector, false, true) + " " + childCssSelector);
            }

            mshtml.IHTMLElement currentNode = element;
            ArrayList           path        = new ArrayList();

            while (currentNode != null)
            {
                string pe = getNode(currentNode, fullPath);
                if (pe != null)
                {
                    path.Add(pe);
                    if (pe.IndexOf("#") != -1)
                    {
                        break;  // Found an ID, no need to go upper, absolute path is OK
                    }
                }
                currentNode = currentNode.parentElement;
            }
            path.Reverse();
            return(join(path, ">"));
        }