private bool FindNonEmptyAttribute(RecEventArgs evt, out String attr, out String attrVal, params Object[] attrNames) { ICustomRecording customRec = this.languageGenerator as ICustomRecording; for (int i = 0; i < attrNames.Length; ++i) { String crntAttr = (String)attrNames[i]; String val = evt.GetAttribute(crntAttr); if (val != "") { attr = crntAttr; if ((attr == "src") && ((customRec == null) || customRec.ShortSrc)) { // For src attribute of the image element keep only the file name if any. int lastSlashIndex = val.LastIndexOf('/'); attrVal = val.Substring(lastSlashIndex + 1); } else { attrVal = val; } return(true); } } return(evt.GetFirstAttribute(out attr, out attrVal)); }
private bool GetAttrToRecord(RecEventArgs evt, out String attr, out String attrVal) { ICustomRecording customRec = this.languageGenerator as ICustomRecording; if (customRec != null) { return(this.FindNonEmptyAttribute(evt, out attr, out attrVal, customRec.GetRecordedAttributes(evt.TagName, evt.InputType))); } // href is for area, src is for img. return(this.FindNonEmptyAttribute(evt, out attr, out attrVal, "id", "name", "uiname", "src", "href", "class")); }
private int ComputeIndex(RecEventArgs evt, String twebstTagName, String attr, String attrVal) { try { String uniqueValue = DateTime.Now.ToString(); IHTMLElement htmlTarget = evt.TargetElement; String searchCondition = null; IElementList elements = null; bool isInnerText = (attr == "innertext"); ICustomRecording customRec = this.languageGenerator as ICustomRecording; htmlTarget.setAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR, uniqueValue, 0); if ((attr != null) && (attrVal != null) && !isInnerText) { searchCondition = String.Format("{0}={1}", attr, attrVal); if ((customRec == null) || !customRec.LocalIndex) { elements = evt.Browser.FindAllElements(twebstTagName, searchCondition); } else { ICore core = CoreWrapper.Instance; IElement targetElem = core.AttachToNativeElement(evt.TargetElement); // Search only elements in current frame. elements = targetElem.parentFrame.FindChildrenElements(twebstTagName, searchCondition); } } else { if ((customRec == null) || !customRec.LocalIndex) { elements = evt.Browser.FindAllElements(twebstTagName, ""); } else { ICore core = CoreWrapper.Instance; IElement targetElem = core.AttachToNativeElement(evt.TargetElement); // Search only elements in current frame. elements = targetElem.parentFrame.FindChildrenElements(twebstTagName, ""); } } int index = 0; int length = elements.length; if (length <= 1) { return(0); } if (!isInnerText) { for (int i = 0; i < length; ++i) { String findIndexAttrValue = (String)elements[i].GetAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR); if (uniqueValue == findIndexAttrValue) { index = i; break; } } } else { // Watir uses innerText but Twebst does not search for innerText. for (int i = 0; i < length; ++i) { String findIndexAttrValue = (String)elements[i].GetAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR); if (uniqueValue == findIndexAttrValue) { break; } if (attrVal == elements[i].nativeElement.innerText) { index++; } } } return(index); } catch { // Something went wrong, give up using index. return(0); } }