/// <summary> /// 复合元素 /// </summary> /// <param name="cpxEle"></param> private IWebElement FindCpxEle(CpxWebELe cpxEle) { IWebElement cpxElement = null; try { string value = $"{cpxEle.HeadValue}/{cpxEle.Value}"; ReadOnlyCollection <IWebElement> eles = GetWebElesInHtml(cpxEle.HeadLocator, value); if (eles == null || eles.Count == 0) { ComArgs.RoLog.WriteLog(LogStatus.LFail, $"FindCpxEle查询到0个控件,FindCpxEle,父值:{cpxEle.HeadValue},子值:{cpxEle.Value}"); } else { if (eles.Count == 1) { cpxElement = eles[0]; } else { if (!string.IsNullOrEmpty(cpxEle.Index)) { cpxElement = eles[Convert.ToInt32(cpxEle.Index) - 1]; } } } } catch (Exception e) { ComArgs.RoLog.WriteLog(LogStatus.LExpt, $"私有方法FindCpxEle发生异常,cpxID:{cpxEle.Id}", e.ToString()); } return(cpxElement); }
/// <summary> /// 返回CpxWebELe的队列 /// </summary> /// <param name="sigXElement"></param> /// <returns></returns> public List <CpxWebELe> GetCpxWebELe(XElement sigXElement) { //复合元素是多个具有通用性质的元素的集合,本质上就是N个元素的集合 List <CpxWebELe> cpxWebELelist = new List <CpxWebELe>(); XElement valueinfo = sigXElement.Element(XName.Get("valueinfo", ComArgs.RoiStr)); XElement element = sigXElement.Element(XName.Get("complexs", ComArgs.RoiStr)); if (element != null && valueinfo != null) { foreach (XElement childEle in element.Elements(XName.Get("cpxchild", ComArgs.RoiStr))) { CpxWebELe cpxWebELe = new CpxWebELe() { Id = childEle.Attribute(XName.Get("id", ComArgs.RoiStr))?.Value ?? Empty, Index = childEle.Attribute(XName.Get("index", ComArgs.RoiStr))?.Value ?? Empty, Value = childEle.Attribute(XName.Get("childvalue", ComArgs.RoiStr))?.Value ?? Empty, HeadIndex = valueinfo.Attribute(XName.Get("index", ComArgs.RoiStr))?.Value ?? Empty, HeadLocator = valueinfo.Attribute(XName.Get("locator", ComArgs.RoiStr))?.Value ?? Empty, HeadValue = valueinfo.Value }; cpxWebELelist.Add(cpxWebELe); } } return(cpxWebELelist); }