public ClickElement(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { _xpaths = GetXPaths(); if (_xpaths.Count == 0 || xel.Element("DestinationPage") == null || !Int32.TryParse(xel.Element("DestinationPage").Value, out _destinationPage)) { throw new Exception("Error in ClickElement xml Action element."); } _startExprSep = GetStartExpSep(); _endExprSep = GetEndExpSep(); _nodeValueType = GetNodeValueType(); // ClickElement treba izvuci href iz targetiranog noda koji vodi na kliknuti link // po defaultu bi trebao pocinjati sa hreaf=", i zavrsiti sa " ukoliko Start i End Expression separatori nisu navedeni if (_startExprSep == null) { _startExprSep = new StartExpressionSeparator("href=\"", false, true); } if (_endExprSep == null) { _endExprSep = new EndExpressionSeparator("\"", false, true); } // isto tako po defaultu uzima NodevalueType OuterHtml ukoliko nije naveden if (_nodeValueType == null) _nodeValueType = NodeValueType.OuterHtml; }
public GetElementValue(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { if (xel.Element("FieldName") == null) { throw new Exception("Error in GetElementValue xml Action element, missing FieldName!"); } _fieldName = xel.Element("FieldName").Value; _predefinedValue = GetPredefinedValue(); if (_predefinedValue == null) { _xpaths = GetXPaths(); if (_xpaths.Count == 0) { throw new Exception("Error in GetElementValue xml Action element, missing XPaths!"); } _nodeValueType = GetNodeValueType(); _startExprSep = GetStartExpSep(); _endExprSep = GetEndExpSep(); _lstReplacements = GetReplacements(); } }
private List<string> _xpaths; // jel treba vise od jednog xpatha?! (se moze link na iducu straicu na nekoj od stranica pojavi u drugom xpathu?!) #endregion Fields #region Constructors public PageList(Page page, XElement xel, int actionIndex) : base(page, xel, actionIndex) { _xpaths = GetXPaths(); if (_xpaths.Count == 0) { throw new Exception("Error in PageList xml Action element. Missing XPath!"); } // pronaci LoadPage element na ovoj stranici List<XElement> actions = (from els in _page.Xdoc.Descendants("Action") where Int32.Parse(els.Element("Page").Value) == _page.PageIndex select els).ToList(); for (int i = 0; i < actions.Count; ++i) { if (actions[i].Element("ActionType").Value == ActionTypeKind.PagePlaceHolder.ToString()) { _pagePlaceHolderIndex = i; break; } } if (_pagePlaceHolderIndex < 0) { throw new Exception("LoadPage action not found for current PageList action!"); } _nodeValueType = GetNodeValueType(); _startExprSep = GetStartExpSep(); _endExprSep = GetEndExpSep(); // PageList treba izvuci href iz targetiranog noda koji vodi na iducu stranicu // po defaultu bi trebao pocinjati sa hreaf=", i zavrsiti sa " ukoliko Start i End Expression separatori nisu navedeni if (_startExprSep == null) { _startExprSep = new StartExpressionSeparator("href=\"", false, true); } if(_endExprSep == null) { _endExprSep = new EndExpressionSeparator("\"", false, true); } }
public string GetNodeValue(string xpath, NodeValueType nodeValueType, StartExpressionSeparator startExprSep, EndExpressionSeparator endExprSep, List<Replacement> lstReplacements) { string retVal = null; HtmlNode node = null; xpath = xpath.Trim(); if (xpath == ".") { node = _anchorLstNodeColl[_anchorLstCurrIndex]; } else { if (xpath.StartsWith("..")) // znaci da ide prema parentu po neki xpath axis (npr ../following-sibling ili ../preceding-sibling) { if (_anchorLstNodeColl == null) { return null; } xpath = _anchorLstNodeColl[_anchorLstCurrIndex].XPath + "/" + xpath; // u tom slucaju treba nadograditi postojeci } node = _htmlDoc.DocumentNode.SelectSingleNode(xpath); // WORKAROUND za slcaj da uleti tbody kojeg obicno nema, ali ga recimo firefox voli dodavati if (node == null && (xpath.Contains("/tbody[1]") || xpath.Contains("/tbody"))) { xpath = xpath.Replace("/tbody[1]", string.Empty); xpath = xpath.Replace("/tbody", string.Empty); node = _htmlDoc.DocumentNode.SelectSingleNode(xpath); } } if (node != null) { switch (nodeValueType) { case NodeValueType.InnerText: retVal = node.InnerText; break; case NodeValueType.InnerHtml: retVal = node.InnerHtml; break; case NodeValueType.OuterHtml: retVal = node.OuterHtml; break; } // 1. PROCESUIRANJE StartExpressionSeparatora i EndExpressionSeparatora if (startExprSep != null) { if (!startExprSep.ValidateSeparator(retVal)) return null; retVal = startExprSep.ProcessValue(retVal); } if (endExprSep != null) { if (!endExprSep.ValidateSeparator(retVal)) return null; retVal = endExprSep.ProcessValue(retVal); } // 2. CISCENJE POVRATNE VRIJEDNOSTI // dekodira web znakove kao sto su '<' i '>', brise visestruko pojavljivanje novih redaka, pretvara tabove u space i brise spaceove ili navodnike sa pocetka i kraja retVal = HttpUtility.HtmlDecode(retVal); retVal = retVal.Replace("\r\n", "\n"); retVal = retVal.Replace("\\r\\n", "\n"); retVal = retVal.Replace("\\n", "\n"); while (retVal.Contains("\n\n")) { retVal = retVal.Replace("\n\n", "\n"); } retVal = retVal.Replace("\t", " "); retVal = retVal.Replace("\\t", " "); retVal = retVal.Trim(); retVal = retVal.Trim('"'); retVal = retVal.Trim('\''); retVal = retVal.Trim(); // 3. PROVODENJE REPLACEMENTA if(lstReplacements != null) { foreach (Replacement rep in lstReplacements) { retVal = rep.Replace(retVal); } } } return retVal; }
public string GetNodeValue(List<string> xpaths, NodeValueType nodeValueType, StartExpressionSeparator startExprSep, EndExpressionSeparator endExprSep, List<Replacement> lstReplacements) { string retVal = null; foreach (string xpath in xpaths) { retVal = GetNodeValue(xpath, nodeValueType, startExprSep, endExprSep, lstReplacements); if (retVal != null) break; } return retVal; }