コード例 #1
0
ファイル: ElementWrapper.cs プロジェクト: cnboker/autorobo
        public void click()
        {
            if (element != null)
            {
                var          nativeElement = (IEElement)element.NativeElement;
                IHTMLElement el            = (IHTMLElement)nativeElement.AsHtmlElement;
                nativeElement.AsHtmlElement.scrollIntoView();
                try
                {
                    string       url    = "";
                    IHTMLDOMNode node   = el as IHTMLDOMNode;
                    bool         _blank = false;
                    if (node.nodeName == "A")
                    {
                        var target = el.getAttribute("target", 0);
                        url = el.getAttribute("href", 0).ToString();
                        //logger.Info("click url:" + url);
                        if (url.ToLower().IndexOf("mailto:") >= 0)
                        {
                            return;
                        }
                        //如果是<a>标签, target="_blank", 则增加导航
                        if (target != null && target.ToString() == "_blank")
                        {
                            _blank = true;
                        }
                    }

                    element.Click();
                    if (_blank)
                    {
                        System.Threading.Thread.Sleep(200);
                        browser.GoTo(url);
                    }
                }
                catch (Exception ex)
                {
                    logger.Fatal(ex);
                }
            }
        }
コード例 #2
0
 public string GetAttribute(string name)
 {
     if (_element != null)
     {
         object value = _element.getAttribute(name, 0);
         if (value != null)
         {
             return(value.ToString());
         }
     }
     return(null);
 }
コード例 #3
0
        public bool IsApplicable(IHTMLElement element, AppSettings.CodeLanguages language)
        {
            if (element == null)
            {
                return(false);
            }

            bool result = true;

            // check if this function page applies to this element
            for (int i = 0; i < nvAttributes.Count; i++)
            {
                string   name      = nvAttributes.Keys[i];
                string[] arrValues = nvAttributes.GetValues(i);
                string   value     = arrValues.Length == 0 ? "" : arrValues[0];

                if (name == "tagName")
                {
                    if (element.tagName.ToLower() != value.ToLower())
                    {
                        result = false;
                        break;
                    }
                }
                else
                {
                    string strValue = element.getAttribute(name, 0) as string;

                    if (strValue == null && value == "null")
                    {
                        continue;
                    }

                    if (strValue == null)
                    {
                        strValue = "";
                    }

                    if (strValue.ToLower() != value.ToLower())
                    {
                        result = false;
                        break;
                    }
                }
            }

            if (!this.Languages.Contains(language.ToString()))
            {
                result = false;
            }

            return(result);
        }
コード例 #4
0
        private string GetTagName(IHTMLElement element)
        {
            string tagName = element.tagName.ToLower();

            if (tagName == "input")
            {
                object typeobject = element.getAttribute("type", 0);
                tagName = typeobject != null?typeobject.ToString() : "TextField";
            }
            tagName = UppercaseFirstLetter(tagName);
            return(tagName);
        }
コード例 #5
0
        public void SetupAttributes(Tuple <XModule, XModuleAttribute, bool> modulePack, IHTMLElement combobox)
        {
            var attribute = modulePack.Item3 ? modulePack.Item1.CreateModuleAttribute() : modulePack.Item2.CreateModuleAttribute();

            var attrName = combobox.getAttribute("value") ?? combobox.getAttribute("name");


            attribute.Name = attrName;

            attribute.Cardinality       = "0-1";
            attribute.BusinessType      = "ComboBox";
            attribute.DefaultActionMode = XTestStepActionMode.Input;

            AddBusinessParam(attribute.CreateConfigurationParam(), "Engine", "Html");
            AddBusinessParam(attribute.CreateConfigurationParam(), "BusinessAssociation", "Descendants");

            foreach (var technical in Scrapper.DecideForTechnicals(combobox))
            {
                AddBusinessParam(attribute.CreateTechnicalIDParam(), technical.Key, technical.Value);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets a particular metadata tag's value.  Return null if the meta tag doesn't exist
        /// in this document.
        /// </summary>
        /// <param name="metaDataName">The name of the metadata element to retrieve</param>
        /// <returns>The value</returns>
        private string GetMetaDataValue(string metaDataName)
        {
            if (!m_metaTableGenerated)
            {
                // Get the meta tags
                IEnumerator tagEnumerator = MetaDataElements.GetEnumerator();

                // Go through all the tags in the head and pull out the meta tags
                while (tagEnumerator.MoveNext())
                {
                    IHTMLElement thisTag = (IHTMLElement)tagEnumerator.Current;

                    // in the meta tags, grab the attributes and put them in the table
                    foreach (string nameAttribute in NAME_ATTRIBUTES)
                    {
                        string name = (string)thisTag.getAttribute(nameAttribute, 0);
                        if (name != null)
                        {
                            name = name.ToUpper(CultureInfo.InvariantCulture);  // for case insensitive comparison
                            string content = (string)thisTag.getAttribute("CONTENT", 0);
                            if (!m_metaTags.ContainsKey(name))
                            {
                                m_metaTags.Add(name, content);
                                break;
                            }
                        }
                    }
                }
                m_metaTableGenerated = true;
            }

            if (m_metaTags.Contains(metaDataName))
            {
                return((string)m_metaTags[metaDataName]);
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
        private void txtAttribute_TextChanged(object sender, EventArgs e)
        {
            string strValue = currentelement.getAttribute(txtAttribute.Text, 0) as string;

            if (strValue == null)
            {
                txtCurrentValue.Text = "NULL";
            }
            else
            {
                txtCurrentValue.Text = strValue;
            }
        }
コード例 #8
0
        protected override PaymentInfo ProcessInProgress(PaymentRequest request)
        {
            PaymentInfo info = request.PaymentInfo;

            if (ReadyToPaste(request))
            {
                return(info);
            }

            if (IsConfirmPage(request))
            {
                IEnumerator e = request.Document.getElementsByTagName("span").GetEnumerator();
                while (e.MoveNext())
                {
                    String html = TrimHtml((e.Current as IHTMLElement).innerHTML).ToLower();
                    if ("numer rachunku:".Equals(html) && e.MoveNext())
                    {
                        info.BankAccountNo = TrimHtml((e.Current as IHTMLElement).innerHTML);
                    }
                    else if ("kwota:".Equals(html) && e.MoveNext())
                    {
                        String amount = TrimHtml((e.Current as IHTMLElement).innerHTML);
                        if (amount.Contains(" "))
                        {
                            amount = amount.Substring(0, amount.LastIndexOf(" ")).Replace(" ", "");
                        }
                        info.AmountPaid = amount;
                        if (info.IsDefinedTransfer == false)
                        {
                            IHTMLElement smsCodeField = request.Document.getElementById("authorization_response");
                            if (smsCodeField != null && "text".Equals(smsCodeField.getAttribute("type", 1)))
                            {
                                info.State = State.IN_PROGRESS_CONFIRM;
                            }
                            else
                            {
                                info.State = State.IN_PROGRESS;
                            }
                        }
                        else
                        {
                            info.State = State.IN_PROGRESS_CONFIRM;
                        }
                        return(info);
                    }
                }
            }

            info.State = State.INVALID;
            return(info);
        }
コード例 #9
0
        public static void _keypress(IHTMLEventObj obj)
        {
            Keys currentKey = (Keys)Enum.Parse(typeof(Keys), obj.keyCode.ToString());

            IHTMLElement current = ((DispHTMLDocument)obj.srcElement.document).activeElement;

            if (CloneInputElement != null)
            {
                if (current == CloneInputElement) //same input
                {
                    sb.Append(current.getAttribute(Finder.valueAttribute, 0));
                }
                else
                {
                    CloneInputElement = (IHTMLElement)((IHTMLDOMNode)current).cloneNode(true);
                    sb.Length         = 0;
                    sb.Append(current.getAttribute(Finder.valueAttribute, 0));
                }
            }
            else
            {
                CloneInputElement = (IHTMLElement)((IHTMLDOMNode)current).cloneNode(true);
                sb.Length         = 0;
                sb.Append(current.getAttribute(Finder.valueAttribute, 0));
            }

            //switch (currentKey)
            //{
            //    case Keys.Enter:
            //        break;
            //    default:
            //        break;

            //}
            //string identify = GetIdentify(obj.srcElement);

            //identify += "action : keyinput ; value :"+obj.keyCode ;
        }
コード例 #10
0
ファイル: IeElement.cs プロジェクト: hbschmidt/IeRobot
        public string GetAttribute(string field)
        {
            string result = "";

            try
            {
                result = Element.getAttribute(field).ToString();
            }
            catch
            {
            }

            return(result);
        }
コード例 #11
0
        private static void screenCapture_HtmlDocumentAvailable(object sender, OpenLiveWriter.Api.HtmlDocumentAvailableEventArgs e)
        {
            IHTMLDocument3 document   = (IHTMLDocument3)e.Document;
            IHTMLElement   mapElement = document.getElementById("map");

            if (mapElement == null || mapElement.getAttribute("loaded", 2) == System.DBNull.Value)
            {
                e.DocumentReady = false;
            }
            else
            {
                e.DocumentReady = true;
            }
        }
コード例 #12
0
 public static string GetAttribute(IHTMLElement ele, string attributeName)
 {
     object attri_obj = ele.getAttribute(attributeName, 0);
     if (attri_obj != null)
     {
         string attri = attri_obj.ToString();
         if (attri != null && !(attri.Equals(string.Empty)))
             return attributeName + " : " + attri;
         else
             return string.Empty;
     }
     else
         return string.Empty;
 }
コード例 #13
0
        public string ActiveElementAttribute(IHTMLElement element, string AttributeName)
        {
            if (element == null)
            {
                return("");
            }

            string strValue = element.getAttribute(AttributeName, 0) as string;

            if (strValue == null)
            {
                strValue = "";
            }
            return(strValue);
        }
コード例 #14
0
        public virtual void AddGridRow(IHTMLElement element)
        {
            int RowIndex = gridElement.RowsCount++;

            gridElement[RowIndex, 0] = new Cell(FindMethods.XPath.ToString(), new TextBox(typeof(string)));
            var id = element.getAttribute("id", 0) == null ? "" : element.getAttribute("id", 0).ToString();

            gridElement[RowIndex, 1] = new Cell(id, new TextBox(typeof(string)));
            var val = XPathFinder.GetXPath(element);

            gridElement[RowIndex, 2] = new Cell(val, new TextBox(typeof(string)));

            var btnDelete = new Button("");

            gridElement[RowIndex, 3] = btnDelete;
            var bmpDelete = new Bitmap(ucBaseElement.GetIconFullPath("db-Delete.bmp"));

            bmpDelete.MakeTransparent(Color.Fuchsia);
            gridElement[RowIndex, 3].Image = bmpDelete;
            var buttonClickEvent = new SourceGrid.Cells.Controllers.Button();

            buttonClickEvent.Executed += DeleteFindButton_Click;
            gridElement[RowIndex, 3].Controller.AddController(buttonClickEvent);
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: hebin123456/SUDA_CWC
        private void btn_fillthree_Click(object sender, EventArgs e)
        {
            IHTMLDocument2 document2 = null;

            for (int i = 0; i < webBrowser1.Document.Window.Frames.Count; i++)
            {
                IHTMLDocument2 temp = (IHTMLDocument2)webBrowser1.Document.Window.Frames[i].Document.DomDocument;
                if ("about:blank" != temp.url.ToString())
                {
                    document2 = temp;
                    break;
                }
            }
            if (document2 == null)
            {
                MessageBox.Show("填充失败, 是否当前不在这个页面?");
            }
            else
            {
                IHTMLDocument3 document3 = (IHTMLDocument3)document2;
                IHTMLElement   card_sno  = document3.getElementById("formWF_YB_NEW_4270_p-card_sno1_0");
                if (card_sno != null)
                {
                    card_sno.setAttribute("value", card_id);
                }
                IHTMLElement card_name2 = document3.getElementById("formWF_YB_NEW_4270_p-card_name1_0");
                if (card_name2 != null)
                {
                    card_name2.setAttribute("value", card_name);
                }
                IHTMLElement card_remark = document3.getElementById("formWF_YB_NEW_4270_p-card_remark1_0");
                if (card_remark != null)
                {
                    card_remark.setAttribute("value", card_num);
                }
                string       WTAMTstring = "";
                IHTMLElement WTAMT       = document3.getElementById("formWF_YB_NEW_4272_p-WTAMT");
                if (WTAMT != null)
                {
                    WTAMTstring = WTAMT.getAttribute("value").ToString();
                }
                IHTMLElement card_amt = document3.getElementById("formWF_YB_NEW_4270_p-card_amt1_0");
                if (card_amt != null)
                {
                    card_amt.setAttribute("value", WTAMTstring);
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// 将选择文本粘帖到主浏览器激活控件上
        /// </summary>
        /// <param name="text"></param>
        private void DefaultRule(string text)
        {
            IHTMLElement active = hostBrowser.GetActiveElement() as mshtml.IHTMLElement;

            if (active is mshtml.HTMLInputElement)
            {
                mshtml.HTMLInputElement input = active as mshtml.HTMLInputElement;
                input.value = text;
            }
            else if (active is mshtml.HTMLTextAreaElement)
            {
                mshtml.HTMLTextAreaElement area = active as mshtml.HTMLTextAreaElement;
                area.innerText = text;
            }
            else if (active is mshtml.HTMLBody)
            {
                string contentEditable = active.getAttribute("contentEditable", 0) as string;
                if (!string.IsNullOrEmpty(contentEditable) && contentEditable == "true")
                {
                    mshtml.HTMLBody body = active as mshtml.HTMLBody;
                    body.innerText = text;
                    return;
                }

                IHTMLElement frame = BrowserExtensions.GetFrame(active) as mshtml.IHTMLElement;
                if (frame != null)
                {
                    mshtml.HTMLBody body = active as mshtml.HTMLBody;
                    body.innerText = text;
                }
            }
            else
            {
                IHTMLElementCollection ec = hostBrowser.GetElementsByTagName(true, "TEXTAREA") as IHTMLElementCollection;
                if (ec.length > 0)
                {
                    mshtml.HTMLTextAreaElement area = ec.item(null, 0) as mshtml.HTMLTextAreaElement;
                    area.innerText = text;
                }
                else
                {
                    ec = hostBrowser.GetElementsByTagName(true, "INPUT") as IHTMLElementCollection;
                    mshtml.HTMLInputElement input = ec.item(null, 0) as mshtml.HTMLInputElement;
                    input.value = text;
                }
            }
        }
コード例 #17
0
        public static Element Create(IHTMLElement element)
        {
            var el = new Element
            {
                Id          = element.id,
                Type        = element.getAttribute("type")?.ToString(),
                Name        = element.getAttribute("name")?.ToString(),
                Class       = element.className,
                Src         = element.getAttribute("src")?.ToString(),
                Href        = element.getAttribute("href")?.ToString(),
                Action      = element.getAttribute("action")?.ToString(),
                Alt         = element.getAttribute("alt")?.ToString(),
                Value       = element.getAttribute("value")?.ToString(),
                Role        = element.getAttribute("role")?.ToString(),
                AriaLabel   = element.getAttribute("aria-label")?.ToString(),
                Tag         = element.tagName,
                Html        = element.outerHTML,
                HtmlElement = element
            };

            return(el);
        }
コード例 #18
0
        private void AdjustResizableContent(int browserWindowHeightPx)
        {
            if (_webView.Document == null)
            {
                return;
            }

            IHTMLElement resizableContentE = ((HTMLDocument)_webView.Document).getElementById("FsprgResizableContent");

            if (resizableContentE == null)
            {
                return;
            }

            IHTMLElement           storePageNavigationE = null;
            IHTMLElementCollection divEs = ((HTMLDocument)_webView.Document).getElementsByTagName("div");

            foreach (IHTMLElement divE in divEs)
            {
                if ("store-page-navigation".Equals(divE.className))
                {
                    storePageNavigationE = divE;
                    break;
                }
            }
            if (storePageNavigationE == null)
            {
                return;
            }

            dynamic resizableContentEStyle = resizableContentE.getAttribute("currentStyle"); // see http://blog.stchur.com/2006/06/21/css-computed-style/
            string  paddingTopStr          = resizableContentEStyle.paddingTop;
            int     paddingTopPx           = int.Parse(paddingTopStr.TrimEnd(new char[] { 'p', 'x' }));
            string  paddingBottomStr       = resizableContentEStyle.paddingBottom;
            int     paddingBottomPx        = int.Parse(paddingBottomStr.TrimEnd(new char[] { 'p', 'x' }));

            int storePageNavigationHeightPx = storePageNavigationE.getAttribute("clientHeight");

            int newHeight = browserWindowHeightPx - paddingTopPx - paddingBottomPx - storePageNavigationHeightPx;

            if (newHeight < 0)
            {
                newHeight = 0;
            }
            resizableContentE.style.height = newHeight + "px";
        }
コード例 #19
0
        /// <summary>
        /// Remove any extraneous attributes from an Attribute Collection
        /// </summary>
        /// <param name="attributes">The attribute collection</param>
        /// <returns>a string representing the attributes with extraneous attributes removed</returns>
        public static void StripAttributes(IHTMLElement element, StringBuilder escapedText)
        {
            foreach (string attr in PreserveAttributes)
            {
                object attrObject = element.getAttribute(attr, 2);                 //note: use 2 as param to get pure attr value
                string attrValue  = null;
                if (attrObject != null)
                {
                    attrValue = attrObject.ToString();
                }

                if (attrValue != null && attrValue != string.Empty)
                {
                    escapedText.Append(" " + attr.ToUpper(CultureInfo.InvariantCulture) + "=\"" + attrValue + "\"");
                }
            }
        }
コード例 #20
0
        // Callback methods

        private void LinkMouseOverHandler(IHTMLEventObj e)
        {
            IHTMLElement a = e.srcElement;

            if ((a == null) || (a.tagName.ToLower() != "a"))
            {
                return;
            }
            string url = a.getAttribute("href");

            if (PACER.IsConvertibleDocumentUrl(url))
            {
                PACER.ConvertDocumentUrl(url, (newurl, docid, caseid, deseqnum, dmid, docnum) => {
                    UploadMetadata(this.court, docid, caseid, deseqnum, dmid, docnum, null);
                });
            }
        }
コード例 #21
0
        void c1Editor1_HtmlEvent(object sender, HtmlEventEventArgs e)
        {
            if (e.Type != C1.Win.C1Editor.HtmlEventTypes.MouseOver) //only MouseOver event is handled
            {
                return;
            }
            bool         isLinked = false;
            IHTMLElement element  = e.HTMLEventObj.SrcElement;

            if (element != null)
            {
                object oClassName = element.getAttribute("className", 0); //get class name of the current element
                if (oClassName is string)
                {
                    string className = oClassName as string;
                    switch (className)
                    {
                    //text input fields
                    case "pubtitle":
                    case "subtitle":
                    case "other":
                    case "pubname":
                    case "isbn":
                        LinkControlToElement(textBox1, element);
                        isLinked = true;
                        break;

                    //date input fields
                    case "date":
                        LinkControlToElement(dateTimePicker1, element);
                        isLinked = true;
                        break;

                    //combobox input fields
                    case "pubcity":
                        LinkControlToElement(comboBox1, element);
                        isLinked = true;
                        break;
                    }
                }
            }
            if (!isLinked)
            {
                HideCurrentVisibleControl(); //hide current control if visible
            }
        }
コード例 #22
0
        /// <summary>
        /// Get the attribute from a document
        /// </summary>
        /// <param name="attribute">Attribute to get</param>
        /// <param name="document2">The IHTMLDocument2</param>
        /// <param name="document3">The IHTMLDocument3</param>
        /// <returns>object with the attribute value</returns>
        public object getAttribute(string attribute)
        {
            IHTMLElement element = null;
            object       retVal  = 0;

            if (!isDTD)
            {
                element = document2.body;
            }
            else
            {
                element = document3.documentElement;
            }
            retVal = element.getAttribute(attribute, 1);
            // Release IHTMLElement com object
            releaseCom(element);
            return(retVal);
        }
コード例 #23
0
ファイル: ImgHelper.cs プロジェクト: snoopy83101/Uzor001
        public static void downImg(string html)
        {
            string         fwqlinshi = System.Web.HttpContext.Current.Server.MapPath("~/upload/HttpDown/");//文件保存在服务器上的临时路径
            IHTMLDocument2 doc       = new HTMLDocumentClass();

            doc.write(new object[] { html });
            doc.close();
            WebClient wc = new WebClient();

            foreach (IHTMLImgElement image in doc.images)
            {
                IHTMLElement element = (IHTMLElement)image;
                string       src     = (string)element.getAttribute("src", 2);
                string       picName = System.IO.Path.GetFileName(src);
                wc.Headers.Add(HttpRequestHeader.Referer, src); //突破反盗链,模拟IE打开页面
                wc.DownloadFile(src, fwqlinshi + picName);      //下载图片到临时路径
            }
        }
コード例 #24
0
 public static bool IsElementMatch(IHTMLElement ele, ElementTag tag, string itemName, string keyword = "")
 {
     itemName = itemName.Trim();
     if (tag == ElementTag.ID)
     {
         return(!string.IsNullOrEmpty(ele.id) && ele.id.Trim().Equals(itemName));
     }
     if (tag == ElementTag.name)
     {
         return((ele.getAttribute("name", 0) != null) && ele.getAttribute("name", 0).ToString().Trim().Equals(itemName));
     }
     if (tag == ElementTag.outerText)
     {
         return(!string.IsNullOrEmpty(ele.outerText) && (ele.outerText.Trim().IndexOf(itemName) != -1));
     }
     if (tag == ElementTag.className)
     {
         return(!string.IsNullOrEmpty(ele.className) && ele.className.Trim().Equals(itemName));
     }
     if (tag == ElementTag.outerHTML)
     {
         return(!string.IsNullOrEmpty(ele.outerHTML) && ele.outerHTML.Trim().Equals(itemName));
     }
     if (tag == ElementTag.value)
     {
         return((ele.getAttribute("value", 0) != null) && ele.getAttribute("value", 0).ToString().Trim().Equals(itemName));
     }
     if (tag == ElementTag.href)
     {
         return((ele.getAttribute("href", 0) != null) && ele.getAttribute("href", 0).ToString().Trim().Equals(itemName));
     }
     if (tag != ElementTag.src)
     {
         return(false);
     }
     if (ele.getAttribute("src", 0) == null)
     {
         return(false);
     }
     return(ele.getAttribute("src", 0).ToString().Trim().Equals(itemName) || (!string.IsNullOrEmpty(keyword) && (ele.getAttribute("src", 0).ToString().Trim().IndexOf(keyword) != -1)));
 }
コード例 #25
0
ファイル: FrameCollection.cs プロジェクト: teknologika/ITiN
        public void Process(IWebBrowser2 webBrowser2)
        {
            // Get the frame element from the parent document
            IHTMLElement frameElement = (IHTMLElement)frameElements.item(index, null);

            string frameName = null;
            string frameId   = null;

            if (frameElement != null)
            {
                frameId   = frameElement.id;
                frameName = frameElement.getAttribute("name", 0) as string;
            }

            Frame frame = new Frame(ie, webBrowser2.Document as IHTMLDocument2, frameName, frameId);

            elements.Add(frame);

            index++;
        }
コード例 #26
0
        void webBrowser_WBLButtonDown(object sender, csExWB.HTMLMouseEventArgs e)
        {
            IHTMLElement el   = e.SrcElement as mshtml.IHTMLElement;
            var          attr = el.getAttribute("__recordmark", 0);

            if (attr != null && attr.ToString() == "1")
            {
                if (!string.IsNullOrEmpty(scriptId))
                {
                    Write(activeElements);
                }
            }
            else
            {
                if (!activeElements.Contains(el))
                {
                    activeElements.Add(el);
                }
            }
        }
コード例 #27
0
        private static bool IsSmartContent(IHTMLElement element)
        {
            // search up the parent heirarchy
            while (element != null)
            {
                if (0 == String.Compare(element.tagName, "div", StringComparison.OrdinalIgnoreCase))
                {
                    string className = element.getAttribute("className", 0) as string;
                    if (className == "wlWriterSmartContent" || className == "wlWriterEditableSmartContent")
                    {
                        return(true);
                    }
                }

                // search parent
                element = element.parentElement;
            }
            // not in smart content
            return(false);
        }
コード例 #28
0
        /// <summary>
        /// 获取元素的类名集合
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private List <string> PrefixedElementClassNames(IHTMLElement element)
        {
            var classAttributes = new List <string>();
            var classAttribute  = element?.getAttribute("classname");

            if (string.IsNullOrEmpty(classAttribute))
            {
                return(classAttributes);
            }
            string[] substrings = Regex.Split(classAttribute, @"\s+");
            foreach (var substring in substrings)
            {
                if (substring != "")
                {
                    classAttributes.Add("$" + substring);
                }
            }

            return(classAttributes);
        }
コード例 #29
0
        public IHTMLElement GetElementByName(string elementName)
        {
            HTMLDocument document = ((HTMLDocument)IE.Document);
            //var element = document.getElementsByName(elementName).GetEnumerator().Current;

            IHTMLElementCollection tags = document.getElementsByTagName("input");

            IEnumerator enumerator = tags.GetEnumerator();

            while (enumerator.MoveNext())
            {
                IHTMLElement element = (IHTMLElement)enumerator.Current;
                if (element.getAttribute("name").ToString() == elementName)
                {
                    return(element);
                }
            }

            throw new ApplicationException($"Element {elementName} not found");
        }
コード例 #30
0
        private void SetMetaData(string metaDataName, string metaDataAttribute, string metaDataValue)
        {
            IEnumerator tagEnumerator = MetaDataElements.GetEnumerator();

            // Go through all the tags in the head and pull out the meta tags
            while (tagEnumerator.MoveNext())
            {
                IHTMLElement thisTag = (IHTMLElement)tagEnumerator.Current;

                // in the meta tag set the right attribute
                foreach (string nameAttribute in NAME_ATTRIBUTES)
                {
                    string name = (string)thisTag.getAttribute(nameAttribute, 0);
                    if (name != null && (name.ToUpper(CultureInfo.InvariantCulture) == metaDataName.ToUpper(CultureInfo.InvariantCulture)))
                    {
                        thisTag.setAttribute(metaDataAttribute, metaDataValue, 0);
                    }
                }
            }
            m_metaTableGenerated = true;
        }
コード例 #31
0
        public static string GetAttribute(IHTMLElement ele, string attributeName)
        {
            object attri_obj = ele.getAttribute(attributeName, 0);

            if (attri_obj != null)
            {
                string attri = attri_obj.ToString();
                if (attri != null && !(attri.Equals(string.Empty)))
                {
                    return(attributeName + " : " + attri);
                }
                else
                {
                    return(string.Empty);
                }
            }
            else
            {
                return(string.Empty);
            }
        }
コード例 #32
0
        private static bool IsDirElement(IHTMLElement e, string direction)
        {
            string dir = e.getAttribute("dir", 2) as string;
            if (null != dir)
                return String.Compare(dir, direction, StringComparison.OrdinalIgnoreCase) == 0;

            return false;
        }
コード例 #33
0
ファイル: HtmlUtil.cs プロジェクト: purplecow/AutoBroswer
 public static bool IsElementMatchType(IHTMLElement ele, string typeName)
 {
     return ((ele.getAttribute("type", 0) != null) && ele.getAttribute("type", 0).ToString().ToLower().Trim().Equals(typeName));
 }
コード例 #34
0
        /// <summary>
        /// Utility for properly printing the start tag for an element.
        /// This utility takes care of including/suppresing attributes and namespaces properly.
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="element"></param>
        private static void printElementStart(HtmlWriter writer, IHTMLElement element)
        {
            string tagName = element.tagName;

            // If there is no tag name, this is mostly an artificial tag reported by mshtml,
            // and not really present in the markup
            // (e.g HTMLTableCaptionClass)
            if (string.IsNullOrEmpty(tagName))
            {
                return;
            }

            //XHTML tags are all lowercase
            tagName = tagName.ToLower(CultureInfo.InvariantCulture);
            //this is a standard HTML tag, so just write it out.
            writer.WriteStartElement(tagName);

            IHTMLDOMNode node = element as IHTMLDOMNode;
            IHTMLAttributeCollection attrs = node.attributes as IHTMLAttributeCollection;
            if (attrs != null)
            {
                foreach (IHTMLDOMAttribute attr in attrs)
                {
                    string attrName = attr.nodeName as string;
                    if (attr.specified)
                    {

                        string attrNameLower = attrName.ToLower(CultureInfo.InvariantCulture);

                        //get the raw attribute value (so that IE doesn't try to expand out paths in the value).
                        string attrValue = element.getAttribute(attrName, 2) as string;
                        if (attrValue == null)
                        {
                            //IE won't return some attributes (like class) using IHTMLElement.getAttribute(),
                            //so if the value is null, try to get the value directly from the DOM Attribute.
                            //Note: we can't use the DOM value by default, because IE will rewrite the value
                            //to contain a fully-qualified path on some attribures (like src and href).
                            attrValue = attr.nodeValue as string;

                            if (attrValue == null)
                            {
                                if ((attrNameLower == "hspace" || attrNameLower == "vspace") && attr.nodeValue is int)
                                {
                                    attrValue = ((int)attr.nodeValue).ToString(CultureInfo.InvariantCulture);
                                }
                                else if (attrNameLower == "style")
                                {
                                    //Avoid bug: Images that are resized with the editor insert a STYLE attribute.
                                    //IE won't return the style attribute using the standard API, so we have to grab
                                    //it from the style object
                                    attrValue = element.style.cssText;
                                }
                                else if (attrNameLower == "colspan")
                                {
                                    attrValue = (element as IHTMLTableCell).colSpan.ToString(CultureInfo.InvariantCulture);
                                }
                                else if (attrNameLower == "rowspan")
                                {
                                    attrValue = (element as IHTMLTableCell).rowSpan.ToString(CultureInfo.InvariantCulture);
                                }
                                else if (attrNameLower == "align" && attr.nodeValue is int)
                                {
                                    // This is not documented anywhere. Just discovered the values empirically on IE7 (Vista).
                                    switch ((int)attr.nodeValue)
                                    {
                                        case 1:
                                            attrValue = "left";
                                            break;
                                        case 2:
                                            attrValue = "center";
                                            break;
                                        case 3:
                                            attrValue = "right";
                                            break;
                                        case 4:
                                            attrValue = "texttop";
                                            break;
                                        case 5:
                                            attrValue = "absmiddle";
                                            break;
                                        case 6:
                                            attrValue = "baseline";
                                            break;
                                        case 7:
                                            attrValue = "absbottom";
                                            break;
                                        case 8:
                                            attrValue = "bottom";
                                            break;
                                        case 9:
                                            attrValue = "middle";
                                            break;
                                        case 10:
                                            attrValue = "top";
                                            break;
                                    }
                                }
                            }
                            Debug.WriteLineIf(attrValue != null && attrName != "id", String.Format(CultureInfo.InvariantCulture, "{0}.{1} attribute value not retreived", tagName, attrName), element.outerHTML);
                        }

                        // Minimized attributes are not allowed, according
                        // to section 4.5 of XHTML 1.0 specification.
                        // TODO: Deal with simple values that are not strings
                        if (attrValue == null && attrNameLower != "id")
                            attrValue = attrName;

                        if (attrName != null && attrValue != null)
                        {
                            //write out this attribute.
                            writer.WriteAttributeString(attrName, attrValue);
                        }
                    }
                }
            }
        }
コード例 #35
0
        internal static void UpdateImageSource(ImagePropertiesInfo imgProperties, IHTMLElement imgElement, IBlogPostImageEditingContext editorContext, ImageInsertHandler imageInsertHandler, ImageDecoratorInvocationSource invocationSource)
        {
            ISupportingFile oldImageFile = null;
            try
            {
                oldImageFile = editorContext.SupportingFileService.GetFileByUri(new Uri((string)imgElement.getAttribute("src", 2)));
            }
            catch (UriFormatException) { }
            if (oldImageFile != null) //then this is a known supporting image file
            {
                using (new WaitCursor())
                {
                    BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editorContext.ImageList, oldImageFile.FileUri);
                    if (imageData != null)
                    {
                        //Create a new ImageData object based on the image data attached to the current image src file.
                        BlogPostImageData newImageData = (BlogPostImageData)imageData.Clone();

                        //initialize some handlers for creating files based on the image's existing ISupportingFile objects
                        //This is necessary so that the new image files are recognized as being updates to an existing image
                        //which allows the updates to be re-uploaded back to the same location.
                        CreateImageFileHandler inlineFileCreator = new CreateImageFileHandler(editorContext.SupportingFileService,
                                                                                              newImageData.InlineImageFile != null ? newImageData.InlineImageFile.SupportingFile : null);
                        CreateImageFileHandler linkedFileCreator = new CreateImageFileHandler(editorContext.SupportingFileService,
                                                                                              newImageData.LinkedImageFile != null ? newImageData.LinkedImageFile.SupportingFile : null);

                        //re-write the image files on disk using the latest settings
                        imageInsertHandler.WriteImages(imgProperties, true, invocationSource, new CreateFileCallback(inlineFileCreator.CreateFileCallback), new CreateFileCallback(linkedFileCreator.CreateFileCallback), editorContext.EditorOptions);

                        //update the ImageData file references
                        Size imageSizeWithBorder = imgProperties.InlineImageSizeWithBorder;

                        //force a refresh of the image size values in the DOM by setting the new size attributes
                        imgElement.setAttribute("width", imageSizeWithBorder.Width, 0);
                        imgElement.setAttribute("height", imageSizeWithBorder.Height, 0);

                        newImageData.InlineImageFile.SupportingFile = inlineFileCreator.ImageSupportingFile;
                        newImageData.InlineImageFile.Height = imageSizeWithBorder.Height;
                        newImageData.InlineImageFile.Width = imageSizeWithBorder.Width;
                        if (imgProperties.LinkTarget == LinkTargetType.IMAGE)
                        {
                            newImageData.LinkedImageFile = new ImageFileData(linkedFileCreator.ImageSupportingFile, imgProperties.LinkTargetImageSize.Width, imgProperties.LinkTargetImageSize.Height, ImageFileRelationship.Linked);
                        }
                        else
                            newImageData.LinkedImageFile = null;

                        //assign the image decorators applied during WriteImages
                        //Note: this is a clone so the sidebar doesn't affect the decorator values for the newImageData image src file
                        newImageData.ImageDecoratorSettings = (BlogPostSettingsBag)imgProperties.ImageDecorators.SettingsBag.Clone();

                        //update the upload settings
                        newImageData.UploadInfo.ImageServiceId = imgProperties.UploadServiceId;

                        //save the new image data in the image list
                        editorContext.ImageList.AddImage(newImageData);
                    }
                    else
                        Debug.Fail("imageData could not be located");
                }
            }

            if (imgProperties.LinkTarget == LinkTargetType.NONE)
            {
                imgProperties.RemoveLinkTarget();
            }
        }
コード例 #36
0
ファイル: FunctionPage.cs プロジェクト: pusp/o2platform
        public bool IsApplicable(IHTMLElement element, AppSettings.CodeLanguages language)
        {
            if (element == null)
            {
                return false;
            }

            bool result = true;

            // check if this function page applies to this element
            for (int i = 0; i < nvAttributes.Count; i++)
            {
                string name = nvAttributes.Keys[i];
                string[] arrValues = nvAttributes.GetValues(i);
                string value = arrValues.Length == 0 ? "" : arrValues[0];

                if (name == "tagName")
                {
                    if (element.tagName.ToLower() != value.ToLower())
                    {
                        result = false;
                        break;
                    }
                }
                else
                {
                    string strValue = element.getAttribute(name, 0) as string;

                    if (strValue==null && value=="null")
                    {
                        continue;
                    }

                    if (strValue == null)
                    {
                        strValue = "";
                    }

                    if (strValue.ToLower() != value.ToLower())
                    {
                        result = false;
                        break;
                    }
                }
            }

            if (!this.Languages.Contains(language.ToString()))
            {
                result = false;
            }

            return result;
        }
コード例 #37
0
        private string WriteStartTag(IHTMLElement element, string style)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<");
            sb.Append(element.tagName);

            if (style != null && style != String.Empty)
            {
                sb.AppendFormat(" style=\"{0}\"", style);
            }

            IHTMLDOMNode node = (IHTMLDOMNode)element;
            IHTMLAttributeCollection attrs = node.attributes as IHTMLAttributeCollection;
            if (attrs != null)
            {
                foreach (IHTMLDOMAttribute attr in attrs)
                {
                    string attrName = attr.nodeName as string;
                    if (attr.specified)
                    {
                        //get the raw attribute value (so that IE doesn't try to expand out paths in the value).
                        string attrValue = element.getAttribute(attrName, 2) as string;
                        if (attrValue == null)
                        {
                            //IE won't return some attributes (like class) using IHTMLElement.getAttribute(),
                            //so if the value is null, try to get the value directly from the DOM Attribute.
                            //Note: we can't use the DOM value by default, because IE will rewrite the value
                            //to contain a fully-qualified path on some attribures (like src and href).
                            attrValue = attr.nodeValue as string;

                            if (attrValue == null)
                            {
                                string upperAttrName = attrName.ToUpperInvariant();
                                if (upperAttrName == "COLSPAN")
                                {
                                    //avoid bug with getting the attr value for column span elements
                                    attrValue = (element as IHTMLTableCell).colSpan.ToString(CultureInfo.InvariantCulture);
                                }
                                else if (upperAttrName == "STYLE")
                                {
                                    //the style attribute value cannot be extracted as a string, so grab its CSS text instead
                                    attrValue = element.style.cssText;
                                }
                            }
                        }

                        if (attrName != null && attrValue != null)
                        {
                            //write out this attribute.
                            sb.AppendFormat(" {0}=\"{1}\"", attrName, attrValue);
                        }
                    }
                }
            }
            sb.Append(">");
            string startTag = sb.ToString();
            return startTag;
        }
コード例 #38
0
 private static string GetParamValue(IHTMLElement param, string[] attributesToSearch)
 {
     string relativePath = null;
     Object name = param.getAttribute("NAME", HTMLAttributeFlags.CaseInSensitive);
     if (name != DBNull.Value)
     {
         // For this element, try to find the attribute containing the value
         for (int i = 0; i < attributesToSearch.Length; i++)
         {
             if (((string)name).ToUpper(CultureInfo.InvariantCulture) == attributesToSearch[i].ToUpper(CultureInfo.InvariantCulture))
             {
                 Object pathObject = param.getAttribute("VALUE", HTMLAttributeFlags.CaseInSensitive);
                 if (pathObject != DBNull.Value)
                 {
                     relativePath = (string)pathObject;
                 }
             }
         }
     }
     return relativePath;
 }
コード例 #39
0
        /// <summary>
        /// Gets the parent link element (if any) for the passed element
        /// </summary>
        /// <param name="element">element</param>
        /// <returns>link element (or null if this element or one of its parents are not a link)</returns>
        private IHTMLElement GetLinkElement(IHTMLElement element)
        {
            // never exhibit this behavior for an image element
            if (SuppressForImages)
            {
                if (element is IHTMLImgElement)
                    return null;
            }

            // search up the parent heirarchy
            while (element != null)
            {
                // if it is an anchor that has an HREF (exclude anchors with only NAME)
                // then stop searching
                if (element is IHTMLAnchorElement)
                {
                    string href = element.getAttribute("href", 2) as string;
                    if (href != null && !(SuppressForLocalUrls && UrlHelper.IsFileUrl(href)))
                    {
                        IHTMLElement3 anchorElement3 = (IHTMLElement3)element;
                        if (!SuppressForNonEditableRegions || anchorElement3.isContentEditable)
                        {
                            return element;
                        }
                    }
                }

                // search parent
                element = element.parentElement;
            }

            // didn't find an anchor
            return null;
        }
コード例 #40
0
        public static string GenerateBlock(string className, string elementId, ISmartContent sContent, bool displayInline, string content, bool noFloat, IHTMLElement element)
        {
            if (string.IsNullOrEmpty(content))
                return "";

            // generate the html to insert
            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.AppendFormat("<div class=\"{0}\"", className);
            if (!string.IsNullOrEmpty(elementId))
                htmlBuilder.AppendFormat(" id=\"{0}\"", elementId);

            if (element != null)
            {
                // Persist the language direction of the smart content if it's explicitly set.
                string currentDirection = element.getAttribute("dir", 2) as string;
                if (!String.IsNullOrEmpty(currentDirection))
                {
                    htmlBuilder.AppendFormat(" dir=\"{0}\"", currentDirection);
                }
            }

            StringBuilder styleBuilder = new StringBuilder();

            if (sContent.Layout.Alignment == Alignment.None
               || sContent.Layout.Alignment == Alignment.Right
               || sContent.Layout.Alignment == Alignment.Left)
            {
                // If the smart content is none/right/left we just use float
                if (!noFloat || sContent.Layout.Alignment != Alignment.None)
                {
                    AppendStyle(noFloat ? "text-align" : "float",
                                sContent.Layout.Alignment.ToString().ToLower(CultureInfo.InvariantCulture),
                                styleBuilder);
                }
            }
            else if (element != null && sContent.Layout.Alignment == Alignment.Center)
            {
                // If the alignment is centered then it needs to make sure float is set to none
                AppendStyle("float", "none", styleBuilder);
                AppendStyle("display", "block", styleBuilder);
                AppendStyle("margin-left", "auto", styleBuilder);
                AppendStyle("margin-right", "auto", styleBuilder);
                AppendStyle("width", element.offsetWidth.ToString(CultureInfo.InvariantCulture), styleBuilder);
            }

            if (displayInline && sContent.Layout.Alignment != Alignment.Center)
                AppendStyle("display", "inline", styleBuilder);

            if (sContent.Layout.Alignment != Alignment.Center)
                AppendStyle("margin", "0px", styleBuilder);

            AppendStyle("padding", ToPaddingString(sContent.Layout), styleBuilder);

            if (styleBuilder.Length > 0)
                htmlBuilder.AppendFormat(" style=\"{0}\"", styleBuilder.ToString());

            htmlBuilder.AppendFormat(">{0}</div>", content);

            return htmlBuilder.ToString();
        }
コード例 #41
0
        private static void AddAttributeToList(string attributeName, IHTMLElement element, ArrayList resources)
        {
            // For this element, try to find the attribute containing a relative path
            string path = null;

            Object pathObject = element.getAttribute(attributeName, HTMLAttributeFlags.DoNotEscapePaths);
            if (pathObject != DBNull.Value)
            {
                path = (string)pathObject;
            }

            // If a valid path was discovered, add it to the list
            if (path != null)
            {
                ResourceUrlInfo info = new ResourceUrlInfo();
                info.ResourceUrl = path;
                info.ResourceType = element.tagName;
                info.InnerText = element.innerText;
                resources.Add(info);
            }
        }
コード例 #42
0
ファイル: HtmlUtil.cs プロジェクト: purplecow/AutoBroswer
 public static bool IsElementMatch(IHTMLElement ele, ElementTag tag, string itemName, string keyword = "")
 {
     itemName = itemName.Trim();
     if (tag == ElementTag.ID)
     {
         return (!string.IsNullOrEmpty(ele.id) && ele.id.Trim().Equals(itemName));
     }
     if (tag == ElementTag.name)
     {
         return ((ele.getAttribute("name", 0) != null) && ele.getAttribute("name", 0).ToString().Trim().Equals(itemName));
     }
     if (tag == ElementTag.outerText)
     {
         return (!string.IsNullOrEmpty(ele.outerText) && (ele.outerText.Trim().IndexOf(itemName) != -1));
     }
     if (tag == ElementTag.className)
     {
         return (!string.IsNullOrEmpty(ele.className) && ele.className.Trim().Equals(itemName));
     }
     if (tag == ElementTag.outerHTML)
     {
         return (!string.IsNullOrEmpty(ele.outerHTML) && ele.outerHTML.Trim().Equals(itemName));
     }
     if (tag == ElementTag.value)
     {
         return ((ele.getAttribute("value", 0) != null) && ele.getAttribute("value", 0).ToString().Trim().Equals(itemName));
     }
     if (tag == ElementTag.href)
     {
         return ((ele.getAttribute("href", 0) != null) && ele.getAttribute("href", 0).ToString().Trim().Equals(itemName));
     }
     if (tag != ElementTag.src)
     {
         return false;
     }
     if (ele.getAttribute("src", 0) == null)
     {
         return false;
     }
     return (ele.getAttribute("src", 0).ToString().Trim().Equals(itemName) || (!string.IsNullOrEmpty(keyword) && (ele.getAttribute("src", 0).ToString().Trim().IndexOf(keyword) != -1)));
 }
コード例 #43
0
        private bool IsClickHandler(IHTMLElement element)
        {
            if (element == null)
                return false;

            string clickCommand = element.getAttribute(CLICK_HANDLER, 0) as string;
            return !String.IsNullOrEmpty(clickCommand);
        }
コード例 #44
0
 private bool IsCenteringNode(IHTMLElement element)
 {
     return GlobalEditorOptions.SupportsFeature(ContentEditorFeature.CenterImageWithParagraph) && element != null &&
         element is IHTMLParaElement && element.getAttribute("align", 2) as string == "center";
 }
コード例 #45
0
        /// <summary>
        /// Gets the parent link element (if any) for the passed element
        /// </summary>
        /// <param name="element">element</param>
        /// <returns>link element (or null if this element or one of its parents are not a link)</returns>
        public static IHTMLAnchorElement GetContainingAnchorElement(IHTMLElement element)
        {
            // search up the parent heirarchy
            while (element != null)
            {
                // if it is an anchor that has an HREF (exclude anchors with only NAME)
                // then stop searching
                if (element is IHTMLAnchorElement)
                {
                    if (element.getAttribute("href", 2) != null)
                        return element as IHTMLAnchorElement;
                }

                // search parent
                element = element.parentElement;
            }

            // didn't find an anchor
            return null;
        }
コード例 #46
0
        /// <summary>
        /// Remove any extraneous attributes from an Attribute Collection
        /// </summary>
        /// <param name="attributes">The attribute collection</param>
        /// <returns>a string representing the attributes with extraneous attributes removed</returns>
        public static void StripAttributes(IHTMLElement element, StringBuilder escapedText)
        {
            foreach (string attr in PreserveAttributes)
            {

                object attrObject = element.getAttribute(attr, 2); //note: use 2 as param to get pure attr value
                string attrValue = null;
                if (attrObject != null)
                    attrValue = attrObject.ToString();

                if (attrValue != null && attrValue != string.Empty)
                {
                    escapedText.Append(" " + attr.ToUpper(CultureInfo.InvariantCulture) + "=\"" + attrValue + "\"");
                }
            }
        }
コード例 #47
0
        public static bool HasMeaningfulAttributes(IHTMLElement element)
        {
            IHTMLAttributeCollection attributeCollection = (IHTMLAttributeCollection)((IHTMLDOMNode)element).attributes;
            foreach (IHTMLDOMAttribute attribute in attributeCollection)
            {
                // For our purposes here anything but size is considered meaningful.
                if (attribute.specified && String.Compare(attribute.nodeName, "size", StringComparison.OrdinalIgnoreCase) != 0)
                    return true;
            }

            // If we get here then, size is the only attribute which could have been specified.
            // Note that size="+0" is not a meaningful attribute
            string sizeAttribute = element.getAttribute("size", 2) as string;
            if (sizeAttribute == null || String.Compare(sizeAttribute, "+0", StringComparison.OrdinalIgnoreCase) == 0)
                return false;

            return true;
        }
コード例 #48
0
ファイル: SkyScanner.cs プロジェクト: jonnyzzz/utils
 private static string SingleInnerText(IHTMLElement element)
 {
   if (String.Equals(element.tagName, "img", StringComparison.CurrentCultureIgnoreCase))
   {
     return element.getAttribute("alt") ?? "";
   }
   return (element.innerText ?? "").Trim();
 }
コード例 #49
0
ファイル: WatinScript.cs プロジェクト: pusp/o2platform
        public string ActiveElementAttribute(IHTMLElement element, string AttributeName)
        {
            if (element == null)
            {
                return "";
            }

            string strValue = element.getAttribute(AttributeName, 0) as string;
            if (strValue == null)
            {
                strValue = "";
            }
            return strValue;
        }
コード例 #50
0
 public bool Filter(IHTMLElement e)
 {
     string attributeName = e.getAttribute(_attributeName, 2) as string;
     return !String.IsNullOrEmpty(attributeName);
 }
コード例 #51
0
 /// <summary>
 /// Check whether the passed HTML element contains the specified attribute
 /// </summary>
 /// <param name="element">element to check</param>
 /// <param name="attribute">name of attribute</param>
 /// <returns>true if the element has the attribute, else false</returns>
 public static bool ElementHasAttribute(IHTMLElement element, string attribute)
 {
     if (element != null)
     {
         object attrib = element.getAttribute(attribute, 0);
         return attrib != DBNull.Value;
     }
     else
     {
         return false;
     }
 }
コード例 #52
0
        private static bool IsSmartContent(IHTMLElement element)
        {
            // search up the parent heirarchy
            while (element != null)
            {
                if (0 == String.Compare(element.tagName, "div", StringComparison.OrdinalIgnoreCase))
                {
                    string className = element.getAttribute("className", 0) as string;
                    if (className == "wlWriterSmartContent" || className == "wlWriterEditableSmartContent")
                        return true;
                }

                // search parent
                element = element.parentElement;
            }
            // not in smart content
            return false;
        }
コード例 #53
0
ファイル: Utils.cs プロジェクト: mradosta/thousandpass
        public static string FindXPath(IHTMLElement node)
        {
            if (node == null) {
                return "";
            }

            string xpath = @"##id=" + node.id;
            try
            {
                try
                {
                    xpath += @";name=" + node.getAttribute("name").ToString();
                }
                catch (Exception e)
                {
                    xpath += @";name=";
                }
                xpath += @";class=" + node.className;

                while (node.parentElement != null)
                {
                    IHTMLElementCollection elements = (IHTMLElementCollection)node.parentElement.children;
                    int c = 1;
                    foreach (IHTMLElement child in elements)
                    {
                        if (node.Equals(child))
                        {
                            break;
                        }
                        else if (node.tagName == child.tagName)
                        {
                            c++;
                        }
                    }

                    // ie bug??
                    if (node.tagName.ToUpper() == "BODY")
                    {
                        c--;
                    }

                    if (c > 1)
                    {
                        xpath = "/" + node.tagName + "[" + c + "]" + xpath;
                    }
                    else
                    {
                        xpath = "/" + node.tagName + xpath;
                    }

                    node = node.parentElement;
                }
            }
            catch (Exception e)
            {
                Utils.l(e);
            }

            return xpath;
        }
コード例 #54
0
        private static void ResetPath(string attributeName, IHTMLElement element, string baseUrl)
        {
            // For this element, try to find the attribute containing a relative path
            string relativePath = null;

            Object pathObject = element.getAttribute(attributeName, HTMLAttributeFlags.DoNotEscapePaths);
            if (pathObject != DBNull.Value)
            {
                if (pathObject is String)
                    relativePath = (string)pathObject;
            }

            // If a relative path was discovered and its not an internal anchor, reset it
            if (relativePath != null && !relativePath.StartsWith("#", StringComparison.OrdinalIgnoreCase) && !UrlHelper.IsUrl(relativePath))
            {
                // Reset the value of the attribute to the escaped Path
                element.setAttribute(attributeName,
                UrlHelper.EscapeRelativeURL(baseUrl, relativePath),
                HTMLAttributeFlags.CaseInSensitive);
            }
        }