/// <summary> /// Checks if source element is a radio and handles the click if it is. /// </summary> private bool TryHandleRadioClick(HtmlElement source, out BrowserInfo browserInfo) { browserInfo = null; HtmlInputElement radio = source as HtmlInputElement; if (radio != null && radio.CachedAttributes.Type == HtmlInputElementType.Radio) { // get all radios with the given name and uncheck them ReadOnlyCollection <HtmlElement> allRadios = source.ParentPage.Elements.FindAll(new { type = "radio", name = radio.Name }); foreach (HtmlElement r in allRadios) { if (r is HtmlInputElement) { ((HtmlInputElement)r).CachedAttributes.Checked = false; } } // check current radio radio.CachedAttributes.Checked = true; browserInfo = new BrowserInfo(); return(true); } return(false); }
public void VerifyGettingTextWithApos() { HtmlPage page = new HtmlPage("Miscellaneous.aspx"); HtmlInputElement input = (HtmlInputElement)page.Elements.Find("TextBoxWithApos"); Assert.AreEqual("I'm here", input.GetAttributes().Value); }
async Task <IImageInfo> LoadAsync(HtmlInputElement inp, Url url, CancellationToken cancel) { var image = await inp.Owner.Options.LoadResource <IImageInfo>(url, cancel).ConfigureAwait(false); inp.FireSimpleEvent(EventNames.Load); return(image); }
/// <summary> /// Emulate entering text by user into input textbox. /// </summary> public static void EnterText(this HtmlInputElement input, string text) { input.Value = text; var evt = input.OwnerDocument.CreateEvent("Event"); evt.InitEvent("change", false, false); input.DispatchEvent(evt); }
private static IEnumerable <string> GetFileNames(HtmlInputElement input) { foreach (var file in input.Files) { var text = $"{file.FileName} ({file.Length} bytes)"; yield return(text); } }
public void SizeIsNullWhenNotPresent() { Dictionary <string, string> attributes = new Dictionary <string, string>(); HtmlElement htmlElement = new HtmlInputElement(attributes, null, null); HtmlInputElementAttributeReader reader = new HtmlInputElementAttributeReader(htmlElement); Assert.IsNull(reader.Size); }
public void CanReadCheckedNotSpecified() { Dictionary <string, string> attributes = new Dictionary <string, string>(); HtmlElement htmlElement = new HtmlInputElement(attributes, null, null); HtmlInputElementAttributeReader reader = new HtmlInputElementAttributeReader(htmlElement); Assert.IsFalse(reader.Checked); }
public CheckboxSample() { var checkbox = new HtmlInputElement { Id = "mycheckbox", Type = "checkbox", Class = "form-check-input" }; var toggle = new HtmlButtonElement { Class = "btn btn-primary", InnerText = "Toggle" }; toggle.On("click", () => { checkbox.Checked = !checkbox.Checked; return(Task.CompletedTask); }); ShadowRoot.Children = new Node[] { new HtmlDivElement { Class = "form-row", Children = new Node[] { new HtmlDivElement { Class = "form-group col-md-2 my-1", Children = new Node[] { new HtmlDivElement { Class = "form-check", Children = new Node[] { checkbox, new HtmlLabelElement { For = checkbox.Id, InnerText = "Check me out" } } } } }, new HtmlDivElement { Class = "form-group col-md-1", Children = new Node[] { toggle } } } } }; }
private static string GetUploadText(HtmlInputElement input) { if (input.Files.Count == 0) { return("No files uploaded"); } return("Uploaded: " + string.Join(", ", GetFileNames(input))); }
public override DomElement CreateElement(string prefix, string localName) { //actual dom implementation *** HtmlElement htmlElement; switch (localName) { case "img": { htmlElement = new HtmlImageElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; case "input": { //input type htmlElement = new HtmlInputElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; case "textarea": { htmlElement = new HtmlTextAreaElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; case "option": { htmlElement = new HtmlOptionElement( this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); } break; default: { htmlElement = new HtmlElement(this, AddStringIfNotExists(prefix), AddStringIfNotExists(localName)); htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName); } break; } return(htmlElement); }
public static HtmlInputElement CreateHtmlInputElement(this HtmlDocument doc, Decorate <HtmlInputElement> dec = null) { var elem = new HtmlInputElement( doc, 0, doc.AddStringIfNotExists("input")); dec?.Invoke(elem); return(elem); }
public void LaraFlushEvent() { var x = new HtmlInputElement(); var builder = new LaraBuilder(x); builder.FlushEvent("click"); x.NotifyEvent("click"); Assert.True(x.Events.TryGetValue("click", out var ev)); Assert.Equal("click", ev !.EventName); }
public void NotifyValueSkipsSameValue() { var input = new HtmlInputElement { Value = "hello" }; input.NotifyValue("hello"); Assert.Equal("hello", input.Value); }
public void NotifyFlagSkipsSameValue() { var input = new HtmlInputElement { Checked = true }; input.NotifyChecked(true); Assert.True(input.Checked); }
public void CanReadCheckedEqualsChecked() { Dictionary <string, string> attributes = new Dictionary <string, string>(); attributes.Add("checked", "checked"); HtmlElement htmlElement = new HtmlInputElement(attributes, null, null); HtmlInputElementAttributeReader reader = new HtmlInputElementAttributeReader(htmlElement); Assert.IsTrue(reader.Checked); }
public void CanReadSize() { Dictionary <string, string> attributes = new Dictionary <string, string>(); attributes.Add("size", "10"); HtmlElement htmlElement = new HtmlInputElement(attributes, null, null); HtmlInputElementAttributeReader reader = new HtmlInputElementAttributeReader(htmlElement); Assert.AreEqual(10, reader.Size); }
public void SetIntAttribute() { var input = new HtmlInputElement { Height = 10 }; Assert.Equal(10, input.Height); input.Height = null; Assert.Null(input.Height); }
/// <summary> /// Executes a form submit /// </summary> private BrowserInfo ExecuteFormSubmit(HtmlFormElement form, HtmlInputElement submitInputElement = null) { Uri url = new Uri(this._emulator.CurrentUri, form.CachedAttributes.Get("action", this._emulator.CurrentUri)); PostDataCollection postdataCollection = form.GetPostDataCollection(submitInputElement); // execute request return(PerformRequest(url.AbsoluteUri, // url form.CachedAttributes.Get("method", "post"), // method "application/x-www-form-urlencoded", // contentType postdataCollection)); // postData }
public void CachedAttributesInheritedType() { string html = @" <html> <input id=foo value=bar> </html> "; HtmlElement element = HtmlElement.Create(html); HtmlInputElement input = (HtmlInputElement)element.ChildElements.Find("foo"); UnitTestAssert.AreEqual("bar", input.CachedAttributes.Value); }
public void InputAttributes() { var input = new HtmlInputElement { MaxLength = 5, Size = 3, Width = 11 }; Assert.Equal(5, input.MaxLength); Assert.Equal(3, input.Size); Assert.Equal(11, input.Width); }
public static void SendPushMessage(Event evt) { //play a click Xdk.player.StartAudio("images/click-5.mp3"); //send the notification FROM the application TO the current user of the application Xdk.notification.SendPushNotification(chosenUsername, HtmlInputElement.GetById("txtMessage").value, "111"); //clear the edit field and update the status message HtmlInputElement.GetById("txtMessage").value = ""; HtmlElement.GetById("spnMessage").innerHTML = "Push Message Sent"; //clear the status message after six seconds ClearTimeout(msgTimeout); msgTimeout = SetTimeout("HideMessage();", 6000); }
public void InputFilesAdd() { var file = new Mock <IFormFile>(); file.Setup(x1 => x1.Name).Returns("abc"); var x = new HtmlInputElement { Type = "file" }; x.AddFile(file.Object); Assert.Single(x.Files); var found = x.Files[0]; Assert.Equal("abc", found.Name); }
/// <summary> /// Checks if source element is a checkbox and handles the click if it is. /// </summary> private bool TryHandleCheckBoxClick(HtmlElement source, out BrowserInfo browserInfo) { browserInfo = null; HtmlInputElement checkbox = source as HtmlInputElement; if (checkbox != null && checkbox.CachedAttributes.Type == HtmlInputElementType.Checkbox) { checkbox.CachedAttributes.Checked = !checkbox.CachedAttributes.Checked; browserInfo = new BrowserInfo(); return(true); } return(false); }
public static HtmlElement CreateHtmlElement(this HtmlDocument doc, string prefix, string localName) { //wellknown name? HtmlElement htmlElement; switch (localName) { case "img": { htmlElement = new HtmlImageElement( doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); } break; case "input": { //input type htmlElement = new HtmlInputElement( doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); } break; case "option": { htmlElement = new HtmlOptionElement( doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); } break; default: { htmlElement = new HtmlElement(doc, doc.AddStringIfNotExists(prefix), doc.AddStringIfNotExists(localName)); htmlElement.WellknownElementName = WellKnownDomNodeMap.EvaluateTagName(htmlElement.LocalName); } break; } return(htmlElement); }
public void RefreshAttributes() { HtmlPage page = new HtmlPage(); page.Navigate("CoreControls.aspx"); HtmlInputElement button = (HtmlInputElement)page.Elements.Find("Button3"); HtmlInputElementAttributeReader attributes = button.GetAttributes(); Assert.AreEqual("Old Button", attributes.Value); Assert.IsNull(attributes.Class); button.Click(); attributes = button.GetAttributes(); Assert.AreEqual("New Button", attributes.Value); Assert.AreEqual("Fuchi", attributes.Class); }
/// <summary> /// Checks if source element is an input type=submit and handles the click if it is /// </summary> private bool TryHandleSubmitButtonClick(HtmlElement source, out BrowserInfo browserInfo) { browserInfo = null; HtmlInputElement button = source as HtmlInputElement; if (button != null && button.CachedAttributes.Type == HtmlInputElementType.Submit) { // retrieve the form HtmlFormElement form = button.FindParentForm(); if (form == null) { throw new InvalidOperationException(CLICKSUBMITBUTTON_FORMNOTFOUND); } browserInfo = ExecuteFormSubmit(form, button); return(true); } return(false); }
public void SetText() { MockCommandExecutor commandExec = new MockCommandExecutor(); _commandExecutorFactory.Setup(m => m.CreateBrowserCommandExecutor(It.IsAny <string>(), It.IsAny <HtmlPage>())).Returns(commandExec); var testPage = new HtmlPage(); HtmlInputElement element = new HtmlInputElement( new Dictionary <string, string>() { { "id", "button1" }, { "type", "textbox" } }, null, testPage); element.SetText("foo"); UnitTestAssert.AreEqual("SetTextBox", commandExec.ExecutedCommands[0].Handler.ClientFunctionName); UnitTestAssert.AreEqual("foo", (string)commandExec.ExecutedCommands[0].Handler.Arguments[0]); }
internal void Post(HtmlFormElement form) { StringBuilder sb = new StringBuilder(); foreach (HtmlElement ele in form.GetElementsByTagName("INPUT")) { if (ele is HtmlInputElement) { HtmlInputElement input = (HtmlInputElement)ele; if (0 == string.Compare(input.Type, "checkbox", true)) { if (!input.Checked) { continue; } } if (0 == string.Compare(input.Type, "radio", true)) { if (!input.Checked) { continue; } } if (sb.Length > 0) { sb.Append("&"); } sb.Append(HttpUtility.UrlEncode(input.Name)); sb.Append("="); sb.Append(HttpUtility.UrlEncode(input.Value)); } } sb.Append("&x=10&y=10"); Post(AbsolizeUrl(form.Action), sb.ToString()); }
public void SetHtmlInputBox(LayoutFarm.Composers.HtmlInputElement htmlInput) { //link to html input _htmlInput = htmlInput; }
public void SetUp() { _document = new HtmlDocument(); _input = (HtmlInputElement)_document.CreateElement("input"); }