Implements an HTML element corresponding with an XElement from the DOM
 public virtual bool SubmitForm(string url = null, HtmlElement clickedElement = null)
 {
     XElement formElem = this.Element.GetAncestorCI("form");
     if (formElem != null)
     {
         FormElement form = this.OwningBrowser.CreateHtmlElement<FormElement>(formElem);
         form.SubmitForm(url, clickedElement);
     }
     return false;
 }
 internal static HtmlElement CreateFor(XElement element)
 {
     HtmlElement result;
     switch (element.Name.LocalName.ToLower())
     {
         case "form":
             result = new FormElement(element);
             break;
         case "input":
             string type = element.GetAttribute("type") ?? "";
             switch (type.ToLower())
             {
                 case "radio":
                     result = new RadioInputElement(element);
                     break;
                 case "checkbox":
                     result = new CheckboxInputElement(element);
                     break;
                 case "submit":
                 case "image":
                 case "button":
                     string buttonType = element.GetAttribute("type");
                     result = new ButtonInputElement(element);
                     break;
                 case "file":
                     result = new FileUploadElement(element);
                     break;
                 default:
                     result = new InputElement(element);
                     break;
             }
             break;
         case "textarea":
             result = new TextAreaElement(element);
             break;
         case "select":
             result = new SelectElement(element);
             break;
         case "option":
             result = new OptionElement(element);
             break;
         case "iframe":
         case "frame":
             var src = element.GetAttributeCI("src");
             if (!string.IsNullOrWhiteSpace(src))
             {
                 result = new FrameElement(element);
             }
             else
             {
                 result = default(HtmlElement);
             }
             break;
         case "a":
             result = new AnchorElement(element);
             break;
         case "label":
             result = new LabelElement(element);
             break;
         case "button":
             result = new ButtonInputElement(element);
             break;
         default:
             result = new HtmlElement(element);
             break;
     }
     return result;
 }
Exemple #3
0
 private bool OnHtmlElementSubmittedAsForm(HtmlElement element, string url)
 {
     return SubmitForm(ObtainAncestor(element.Element, "form"), element.Element, url);
 }
        public virtual bool SubmitForm(string url = null, HtmlElement clickedElement = null)
        {
            XElement formElem = null;
            if (this.Element.HasAttributeCI("form"))
            {
                formElem = this.Element.Document.Descendants().Where(e => e.HasAttributeCI("id") && e.GetAttributeCI("id").Equals(this.Element.GetAttributeCI("form"))).First();
            }
            else
            {
                formElem = this.Element.GetAncestorCI("form");
            }

            if (formElem != null)
            {
                FormElement form = this.OwningBrowser.CreateHtmlElement<FormElement>(formElem);
                return form.SubmitForm(url, clickedElement);
            }
            return false;
        }
Exemple #5
0
 void htmlElement_AspNetPostBackLinkClicked(HtmlElement element, string name)
 {
     Find(ElementType.TextField, FindBy.Name, "__EVENTTARGET").Value = name;
     OnHtmlElementSubmittedAsForm(element, null);
 }
Exemple #6
0
        private ClickResult htmlElement_Clicked(HtmlElement element)
        {
            switch(element.TagName.ToLower())
            {
                case "a": return ClickLink(element.Element);
                case "input":
                    switch(element.InputType)
                    {
                        case "radio": return CheckRadioButton(element.Element);
                        case "checkbox": return CheckCheckbox(element.Element);
                        case "image":
                        case "button":
                        case "submit": return element.SubmitForm() ? ClickResult.SucceededNavigationComplete : ClickResult.SucceededNavigationError;
                        default: return ClickResult.SucceededNoNavigation;
                    }
                case "button":
                    switch (element.InputType)
                    {
                        case "submit": return element.SubmitForm() ? ClickResult.SucceededNavigationComplete : ClickResult.SucceededNavigationError;
                        default: return ClickResult.SucceededNoNavigation;
                    }
            }

            return ClickResult.SucceededNoNavigation;
        }
Exemple #7
0
 internal HtmlElement CreateHtmlElement(XElement element)
 {
     var htmlElement = new HtmlElement(element);
     htmlElement.Clicked += htmlElement_Clicked;
     htmlElement.FormSubmitted += OnHtmlElementSubmittedAsForm;
     htmlElement.AspNetPostBackLinkClicked += htmlElement_AspNetPostBackLinkClicked;
     return htmlElement;
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlResult"/> class.
 /// </summary>
 /// <param name="result">A <see cref="HtmlElement"/></param>
 /// <param name="browser">The browser instance where the HTML results was found</param>
 internal HtmlResult(HtmlElement result, Browser browser)
 {
     this.currentElement = result;
     this.browser        = browser;
     this.resultList     = new List <HtmlElement>(new[] { result });
 }
Exemple #9
0
 internal HtmlResult(HtmlElement result, Browser browser)
 {
     _current = result;
     _browser = browser;
     _list    = new List <HtmlElement>(new[] { result });
 }
Exemple #10
0
 private bool OnHtmlElementSubmittedAsForm(HtmlElement element, string url)
 {
     return(SubmitForm(ObtainAncestor(element.Element, "form"), element.Element, url));
 }
Exemple #11
0
 void htmlElement_AspNetPostBackLinkClicked(HtmlElement element, string name)
 {
     Find(ElementType.TextField, FindBy.Name, "__EVENTTARGET").Value = name;
     OnHtmlElementSubmittedAsForm(element, null);
 }