protected virtual void FillTextElement(IHTMLElement element, string value) { switch (element.tagName) { case "INPUT": IHTMLInputElement textElement = element as IHTMLInputElement; if (string.IsNullOrEmpty(textElement.value)) { textElement.value = value; this.InvokeOnChange(element); this.FillRecords[(int)ElementType.Text].RecordCount++; } break; case "TEXTAREA": IHTMLTextAreaElement textAreaElement = element as IHTMLTextAreaElement; if (string.IsNullOrEmpty(textAreaElement.value)) { textAreaElement.value = value; this.InvokeOnChange(element); this.FillRecords[(int)ElementType.Text].RecordCount++; } break; } }
public void Type() { CQ cq = CQ.Create("<textarea type=useless>Foo that bar</textarea>"); IHTMLTextAreaElement textArea = cq["textarea"].FirstElement() as IHTMLTextAreaElement; Assert.IsNotNull(textArea); Assert.AreEqual("textarea", textArea.Type); Assert.AreEqual("useless", textArea.GetAttribute("type")); }
}//end BeginFillProtected protected override void FillTextElement(IHTMLElement element, string value) { switch (element.tagName) { case "INPUT": IHTMLInputElement textElement = element as IHTMLInputElement; textElement.value = value; this.InvokeOnChange(element); this.FillRecords[(int)ElementType.Text].RecordCount++; break; case "TEXTAREA": IHTMLTextAreaElement textAreaElement = element as IHTMLTextAreaElement; textAreaElement.value = value; this.InvokeOnChange(element); this.FillRecords[(int)ElementType.Text].RecordCount++; break; } }
private void FillElement(FillParameter parameter, ref string value) { //if (parameter.Type != Matcher.TYPE_FORM) //{ // if (parameter.Value == "上传图片") // { // if (string.IsNullOrEmpty(value)) // return; // string file = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value); // if (System.IO.File.Exists(file) == false) // { // base.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", file), parameter.ParameterName)); // return; // } // } //} //base.FillElement(parameter, value); if (parameter == null) { return; } IHTMLElement element = null; if (parameter.ParameterName == null || base.DataTable.Contains(parameter.ParameterName) == false) { value = DefaultValue; } if (parameter.Type != Matcher.TYPE_FORM) { element = base.GetElement(parameter, _formIndex); if (element == null) { this.FillRecords.Add(new FillRecord(GetElementType(parameter.Type), RecordType.Failed, "未找到此元素", parameter.ParameterName)); return; } else if (parameter.Value == "上传图片") { if (string.IsNullOrEmpty(value)) { return; } string file = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value); if (System.IO.File.Exists(file) == false) { this.FillRecords.Add(new FillRecord(ElementType.File, RecordType.Failed, string.Format("文件{0}不存在", value), parameter.ParameterName)); return; } } ((IHTMLElement2)element).focus(); } if (string.IsNullOrEmpty(parameter.SplitExpr) == false && string.IsNullOrEmpty(value) == false) { Match match = Regex.Match(value, parameter.SplitExpr, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase); if (match.Success) { value = match.Groups["value"].Value; } } _currentFillValue = value; switch (parameter.Type) { case Matcher.TYPE_FORM: if (base.GetElement(parameter, -1) != null) { _formIndex++; } break; case Matcher.TYPE_RADIO: IHTMLInputElement radioElement = element as IHTMLInputElement; radioElement.@checked = true; this.FillRecords[(int)ElementType.Radio].RecordCount++; break; case Matcher.TYPE_SELECT: if (FillSelectElement(parameter, ref value)) { this.FillRecords[(int)ElementType.Select].RecordCount++; } else { this.FillRecords.Add(new FillRecord(ElementType.Select, RecordType.Failed, string.Format("下拉框中不包含选项 {0}", value), parameter.ParameterName)); } break; case Matcher.TYPE_A: element.click(); break; case Matcher.TYPE_FILE: value = string.IsNullOrEmpty(base.DataFilePath) ? value : string.Format("{0}\\{1}", base.DataFilePath, value); _currentFillValue = value; if (System.IO.File.Exists(value)) { element.click(); this.FillRecords[(int)ElementType.File].RecordCount++; } break; case Matcher.TYPE_SUBMIT: case Matcher.TYPE_BUTTON: case "BUTTON/SUBMIT": IHTMLInputElement fileElement = element as IHTMLInputElement; element.click(); break; case Matcher.TYPE_TEXTAREA: IHTMLTextAreaElement textAreaElement = element as IHTMLTextAreaElement; textAreaElement.value = value; this.FillRecords[(int)ElementType.Text].RecordCount++; break; case Matcher.TYPE_TEXT: case Matcher.TYPE_PASSWORD: IHTMLInputElement textElement = element as IHTMLInputElement; textElement.value = value; this.FillRecords[(int)ElementType.Text].RecordCount++; break; } }
public TextAreaElement(IHTMLTextAreaElement htmlTextAreaElement) { this.htmlTextAreaElement = htmlTextAreaElement; }