Exemple #1
0
        /// <summary>
        ///     Creates the HTML element.
        /// </summary>
        /// <typeparam name="T">The type of the T.</typeparam>
        /// <param name="searchContext">The search context.</param>
        /// <returns>The value.</returns>
        public static T CreateHtmlElement <T>(ISearchContext searchContext) where T : HtmlElement
        {
            var htmlElementInstance = (T)HtmlElementFactory.CreateHtmlElementInstance(typeof(T));

            PopulateHtmlElement(htmlElementInstance, new HtmlElementLocatorFactory(searchContext));
            return(htmlElementInstance);
        }
Exemple #2
0
        /// <summary>
        ///     Creates the page object.
        /// </summary>
        /// <typeparam name="T">The type of the T.</typeparam>
        /// <param name="driver">The driver.</param>
        /// <returns>The value.</returns>
        public static T CreatePageObject <T>(IWebDriver driver)
        {
            var page = (T)HtmlElementFactory.CreatePageObjectInstance(typeof(T), driver);

            PopulatePageObject(page, new HtmlElementLocatorFactory(driver));
            return(page);
        }
Exemple #3
0
        /// <summary>
        /// Bind this instance to a new DomDocument created from HTML using the specified parsing mode.
        /// </summary>
        ///
        /// <param name="html">
        /// The HTML.
        /// </param>
        /// <param name="htmlParsingMode">
        /// The HTML parsing mode.
        /// </param>

        protected void CreateNewDocument(char[] html, HtmlParsingMode htmlParsingMode)
        {
            Document = new DomDocument(html, htmlParsingMode);
            HtmlElementFactory.ReorganizeStrandedTextNodes(Document);
            AddSelection(Document.ChildNodes);
            FinishCreatingNewDocument();
        }
        protected override Action <JetBrains.TextControl.ITextControl> ExecutePsiTransaction(JetBrains.ProjectModel.ISolution solution, JetBrains.Application.Progress.IProgressIndicator progress)
        {
            if (!Highlighting.IsValid())
            {
                return(null);
            }

            var node             = Highlighting.Node;
            var badWordTextRange = Highlighting.Range.TextRange;

            var newText = StringUtil.ReplaceSection(
                node.GetText(),
                Suggestion,
                badWordTextRange.StartOffset - node.GetDocumentRange().TextRange.StartOffset,
                badWordTextRange.Length
                );

            if (node is TreeElement)
            {
                var elementFactory = HtmlElementFactory.GetInstance(node.Language);
                var newElements    = elementFactory.CompileText(newText, node).ToList();
                if (newElements.Count > 0)
                {
                    var recentNode = ModificationUtil.ReplaceChild(node, newElements[0]);
                    for (int i = 1; i < newElements.Count; i++)
                    {
                        recentNode = ModificationUtil.AddChildAfter(recentNode.Parent, recentNode, newElements[i]);
                    }
                }
                return(null);
            }
            return(null);
        }
        private IList <TypifiedElement> GetElements()
        {
            IList <TypifiedElement> typifiedElements = new List <TypifiedElement>();
            IList <IWebElement>     elements         = locator.FindElements();
            int elementNumber = 0;

            foreach (IWebElement element in elements)
            {
                TypifiedElement typifiedElement     = HtmlElementFactory.CreateTypifiedElementInstance(elementType, element);
                string          typifiedElementName = string.Format("{0} {1}", name, elementNumber);
                typifiedElement.Name = typifiedElementName;
                typifiedElements.Add(typifiedElement);
                elementNumber++;
            }
            return(typifiedElements);
        }
        /// <summary>
        ///     Gets the elements.
        /// </summary>
        /// <returns>The value.</returns>
        private IList <TypifiedElement> GetElements()
        {
            IList <TypifiedElement> typifiedElements = new List <TypifiedElement>();
            IList <IWebElement>     elements         = Locator.FindElements();
            var elementNumber = 0;

            foreach (var element in elements)
            {
                var typifiedElement     = HtmlElementFactory.CreateTypifiedElementInstance(elementType, element);
                var typifiedElementName = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Name, elementNumber);
                typifiedElement.Name = typifiedElementName;
                typifiedElements.Add(typifiedElement);
                elementNumber++;
            }

            return(typifiedElements);
        }
        public static T Create <T>(IWebDriver driver)
        {
            object result;
            Type   type = typeof(T);

            if (HtmlElementUtils.IsHtmlElement(type))
            {
                result = HtmlElementFactory.CreateHtmlElementInstance(type);
                PopulateHtmlElement((HtmlElement)result, new HtmlElementLocatorFactory(driver));
            }
            else
            {
                result = (T)HtmlElementFactory.CreatePageObjectInstance(type, driver);
                PopulatePageObject(result, new HtmlElementLocatorFactory(driver));
            }
            return((T)result);
        }
        private IList <HtmlElement> GetElements()
        {
            IList <HtmlElement> htmlElements = new List <HtmlElement>();
            IList <IWebElement> elements     = locator.FindElements();
            int elementNumber = 0;

            foreach (IWebElement element in elements)
            {
                HtmlElement htmlElement = HtmlElementFactory.CreateHtmlElementInstance(elementType);
                htmlElement.WrappedElement = element;
                string htmlElementName = string.Format("{0} {1}", name, elementNumber);
                htmlElement.Name = htmlElementName;
                PageFactory.InitElements(new HtmlElementDecorator(element), htmlElement);
                htmlElements.Add(htmlElement);
                elementNumber++;
            }
            return(htmlElements);
        }
        /// <summary>
        ///     Gets the elements.
        /// </summary>
        /// <returns>The value.</returns>
        private IList <HtmlElement> GetElements()
        {
            IList <HtmlElement> htmlElements = new List <HtmlElement>();
            IList <IWebElement> elements     = Locator.FindElements();
            var elementNumber = 0;

            foreach (var element in elements)
            {
                var htmlElement = HtmlElementFactory.CreateHtmlElementInstance(elementType);
                htmlElement.WrappedElement = element;
                var htmlElementName = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Name, elementNumber);
                htmlElement.Name = htmlElementName;
                PageFactory.InitElements(new HtmlElementDecorator(element), htmlElement);
                htmlElements.Add(htmlElement);
                elementNumber++;
            }

            return(htmlElements);
        }
Exemple #10
0
        /// <summary>
        ///     Populates the HTML element.
        /// </summary>
        /// <param name="htmlElement">The HTML element.</param>
        /// <param name="locatorFactory">The locator factory.</param>
        private static void PopulateHtmlElement(HtmlElement htmlElement, CustomElementLocatorFactory locatorFactory)
        {
            var htmlElementType = htmlElement.GetType();

            // Create locator that will handle Block annotation
            var locator = locatorFactory.CreateLocator(htmlElementType);

            // The next line from Java code located here till I find a solution to replace ClassLoader
            // ClassLoader htmlElementClassLoader = htmlElement.getClass().getClassLoader();

            // Initialize block with IWebElement proxy and set its name
            var elementName = HtmlElementUtils.GetElementName(htmlElementType);

            var elementToWrap = HtmlElementFactory.CreateNamedProxyForWebElement(locator, elementName);

            htmlElement.WrappedElement = elementToWrap;
            htmlElement.Name           = elementName;

            // Initialize elements of the block
            PageFactory.InitElements(new HtmlElementDecorator(elementToWrap), htmlElement);
        }
Exemple #11
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            IHtmlTagHeader tagHeader = GetTag();

            if (tagHeader == null)
            {
                return(null);
            }

            // The easiest way to create an attribute is to create an HTML tag with an attribute in it
            // and then get the attribute from the tag.
            HtmlElementFactory factory = HtmlElementFactory.GetInstance(tagHeader.Language);
            IHtmlTag           dummy   = factory.CreateHtmlTag("<tag id=\"\"/>", tagHeader);
            ITagAttribute      idAttr  = dummy.Attributes.Single();

            tagHeader.AddAttributeBefore(idAttr, null);

            // continuation to do after transaction committed
            return(textControl =>
                   // move cursor inside new created id attribute
                   textControl.Caret.MoveTo(idAttr.ValueElement.GetDocumentRange().TextRange.StartOffset, CaretVisualPlacement.Generic));
        }
Exemple #12
0
 public BuildTagService()
 {
     _factory = new HtmlElementFactory();
 }
        private void HandleAdditionalOperations(AdditionalOperations[] additionalOperation, char character, StringBuilder buffer)
        {
            if (additionalOperation == null)
            {
                return;
            }

            foreach (AdditionalOperations value in additionalOperation)
            {
                switch (value)
                {
                case AdditionalOperations.ClearBuffer:
                {
                    buffer.Clear();
                    break;
                }

                case AdditionalOperations.AddCharacterToBuffer:
                {
                    buffer.Append(character);
                    break;
                }

                case AdditionalOperations.PushHtmlElementToStack:
                {
                    var htmlElement = HtmlElementFactory.CreateByName(buffer.ToString());

                    //Create fake parent element if only body is parsed
                    if (!stack.Any() && !htmlElement.Name.Equals(ParsingRules.SignificantHtmlTagNames.html))
                    {
                        //Create fake parent element
                        HtmlElement fakeParentElement = new HtmlElement(ParsingRules.SignificantHtmlTagNames.html);
                        stack.Push(fakeParentElement);
                    }

                    if (stack.TryPeek(out var topHtmlElement))
                    {
                        //case when <li> not closed and another <li> appeared
                        if (ParsingRules.HtmlAutoClosingTags.Contains(topHtmlElement.Name) && topHtmlElement.Name.Equals(htmlElement.Name))
                        {
                            lastPopedElementFromStack = stack.Pop();
                            stack.TryPeek(out topHtmlElement);
                        }

                        if (topHtmlElement != null)
                        {
                            topHtmlElement.AddElement(htmlElement);
                        }
                    }

                    stack.Push(htmlElement);

                    break;
                }

                case AdditionalOperations.PopHtmlElementFromStack:
                {
                    lastPopedElementFromStack = stack.Pop();
                    //case when <li> not closed and </ul> closing tag appears
                    while (ParsingRules.HtmlAutoClosingTags.Contains(lastPopedElementFromStack.Name) && stack.Any() &&
                           !lastPopedElementFromStack.Name.Equals(buffer.ToString()))
                    {
                        lastPopedElementFromStack = stack.Pop();
                    }

                    if (!lastPopedElementFromStack.Name.Equals(buffer.ToString()))
                    {
                        throw new InvalidSyntaxException($"Invalid syntax at line: {CurrentLine}, position: {CurrentIndexInLine}");
                    }
                    break;
                }

                case AdditionalOperations.PopSelfClosingElementFromStack:
                {
                    lastPopedElementFromStack            = stack.Pop();
                    lastPopedElementFromStack.SelfClosed = true;
                    break;
                }

                case AdditionalOperations.CheckIfAutoClosingTag:
                {
                    //Pop elements which can be closed without closing tag - meta, img
                    if (stack.TryPeek(out var topHtmlElement))
                    {
                        if (ParsingRules.HtmlTagsForbiddenToBeClosed.Contains(topHtmlElement.Name))
                        {
                            lastPopedElementFromStack            = stack.Pop();
                            lastPopedElementFromStack.SelfClosed = true;
                        }
                    }

                    break;
                }

                case AdditionalOperations.CreateAttributeName:
                {
                    stack.Peek().Attributes.Add(new HtmlAttribute(buffer.ToString()));
                    break;
                }

                case AdditionalOperations.CreateAttributeValue:
                {
                    var topHtmlElement = stack.Peek();
                    var attribute      = topHtmlElement.Attributes.LastOrDefault();
                    attribute.Value = buffer.ToString();

                    if (attribute.Name.ToLower().Equals(ParsingRules.HtmlAttributeNames.Value))
                    {
                        topHtmlElement.Value = attribute.Value;
                    }

                    break;
                }

                case AdditionalOperations.CreateElementValue:
                {
                    if (stack.TryPeek(out var topHtmlElement))
                    {
                        topHtmlElement.Value += character;
                    }

                    break;
                }
                }
            }
        }
 public IEnumerable <TElement> QueryElements <TElement>(string query)
     where TElement : HtmlElement
 {
     return(HtmlElementFactory.CreateHtmlElements <TElement>(Element.querySelectorAll(query)));
 }
 public TElement GetChild <TElement>(int index = 0)
     where TElement : HtmlElement
 {
     return(HtmlElementFactory.CreateHtmlElement <TElement>(Element.children[index]));
 }
Exemple #16
0
        HTMLElement Create(string tagName)
        {
            var doc = new Document();

            return(HtmlElementFactory.Create(tagName, doc));
        }