/// <summary> /// 此方法是查找iframe下的a标签,查找规则是根据提供的searchKey查找指定的属性内容,默认直返回第一个被查找到的元素 /// </summary> /// <param name="iframe"></param> /// <param name="searchKey"></param> /// <param name="isFindByTitle"></param> /// <param name="isFindByClassName"></param> /// <returns></returns> public HTMLAnchorElementClass Get_Alink_From_IFrame(HTMLFrameElementClass iframe, string searchKey, bool isFindByTitle = true, bool isFindByClassName = false) { HTMLAnchorElementClass aLink = null; IHTMLElementCollection aLinkElementCollection; IHTMLDocument2 doc; HTMLBodyClass bodyClass; doc = iframe.contentWindow.document; bodyClass = (HTMLBodyClass)doc.body; aLinkElementCollection = bodyClass.getElementsByTagName("a"); foreach (HTMLAnchorElementClass item in aLinkElementCollection) { if (isFindByTitle) { if (null != item.title && item.title.Equals(searchKey)) { aLink = item; break; } } else if (isFindByClassName) { if (null != item.className && item.className.Equals(searchKey)) { aLink = item; break; } } } return(aLink); }
public string Execute(HtmlElement linkToClick) { try { HTMLAnchorElementClass linkElement = (HTMLAnchorElementClass)linkToClick.DomElement; linkElement.click(); } catch (Exception ex) { return(String.Format("Unable to click link: {0}", ex.Message)); } return("Link was clicked, new page opened..."); }
public bool onclick(IHTMLEventObj pEvtObj) { string code = null; if (pEvtObj.srcElement is HTMLAnchorElementClass) { HTMLAnchorElementClass a = (HTMLAnchorElementClass)pEvtObj.srcElement; if (string.IsNullOrEmpty(a.id) == false) { code = watirMaker.ClickLink(":id", a.id); } else if (string.IsNullOrEmpty(a.name) == false) { code = watirMaker.ClickLink(":name", a.name); } else if (string.IsNullOrEmpty(a.innerText) == false) { code = watirMaker.ClickLink(":text", a.innerText); } else { code = watirMaker.ClickLink(":url", a.href); } } else if (pEvtObj.srcElement is HTMLButtonElementClass) { HTMLButtonElementClass b = pEvtObj.srcElement as HTMLButtonElementClass; if (b.id != null && b.id.Length > 0) { code = watirMaker.ClickButton(":id", b.id, b.value); } else //use name or value { code = watirMaker.ClickButton(":name", b.name, b.value); } } else if (pEvtObj.srcElement is HTMLInputElementClass) { HTMLInputElementClass text = pEvtObj.srcElement as HTMLInputElementClass; string log = String.Format("Focus Out \"{0}\"", (text.id != null ? text.id : text.name)); switch (text.type) { case "radio": if (text.id != null && text.id.Length > 0) { code = watirMaker.Radio(":id", text.id, text.value); } else if (text.name != null && text.name.Length > 0) //use name { code = watirMaker.Radio(":name", text.name, text.value); } break; case "submit": case "button": case "image": if (text.id != null && text.id.Length > 0) { code = watirMaker.ClickButton(":id", text.id, text.value); } else //use name or value { code = watirMaker.ClickButton(":name", text.name, text.value); } break; } formBackpointer.LogEvent(log); } if (code != null) { formBackpointer.SuppressOneGoto(); formBackpointer.AppendText(code); } return(true); }