/// <summary> /// Dumps the element ids. /// </summary> /// <param name="document">The document.</param> /// <param name="logWriter">The log writer.</param> public static void DumpElements(Document document, ILogWriter logWriter) { logWriter.LogAction("Dump:"); IHTMLElementCollection elements = elementCollection(document); foreach (IHTMLElement e in elements) { logWriter.LogAction("id = " + e.id); } }
/// <summary> /// Dumps the elements with HTML source. /// </summary> /// <param name="document">The document.</param> /// <param name="logWriter">The log writer.</param> public static void DumpElementsWithHtmlSource(Document document, ILogWriter logWriter) { logWriter.LogAction("Dump:=================================================="); IHTMLElementCollection elements = elementCollection(document); foreach (IHTMLElement e in elements) { logWriter.LogAction("------------------------- " + e.id); logWriter.LogAction(e.outerHTML); } }
public static TElement TryFind <TElement>(this WC.Document browser, string id) where TElement : WC.Element { var element = browser.ElementOfType <TElement>(id); element.WaitUntilExists(5); if (!element.Exists) { MessageBox.Show(id + " " + typeof(TElement).Name + " is not found"); } return(element); }
private static void SetDocument() { _document = _ie.DomContainer; if (!String.IsNullOrEmpty(_control.HTMLDialog)) { _document = _ie.HtmlDialog(Find.ByTitle(new Regex(_control.HTMLDialog))); } if (!String.IsNullOrEmpty(_control.Frame)) { string[] frames = _control.Frame.Split(','); foreach (string frame in frames) { try { _document = _document.Frame(Find.BySrc(new Regex(frame))); } catch { _document = _document.Frame(Find.ById(new Regex(frame))); } } } }
public static void SetValue(string controlString, bool value) { WebActionSetUp(controlString); switch (_control.ControlType) { case "checkbox": _document.CheckBox(_control.WatinAttribute).Checked = value; WaitForAsyncPostBackToComplete(); break; case "radiobutton": _document.RadioButton(_control.WatinAttribute).Checked = value; WaitForAsyncPostBackToComplete(); break; default: throw new NotImplementedException("he control type has not been implemented in Stax.Controller.Watin SetValue()"); } _document = BrowserController.DomContainer; }
public static void SetValue(string controlString, string value) { WebActionSetUp(controlString); switch (_control.ControlType) { case "input": case "text": if (!string.IsNullOrEmpty(value)) { _document.TextField(_control.WatinAttribute).Value = value ?? string.Empty; WaitForAsyncPostBackToComplete(); } break; case "typetext": if (!string.IsNullOrEmpty(value)) { _document.TextField(_control.WatinAttribute).TypeText(value ?? string.Empty); WaitForAsyncPostBackToComplete(); } break; case "select": // if the value to set is empty, ignore it. if (!string.IsNullOrEmpty(value)) { WaitForAsyncPostBackToComplete(); _document.SelectList(_control.WatinAttribute).Select(value); WaitForAsyncPostBackToComplete(); } break; case "checkbox": // if the value to set is empty, ignore it. if (!string.IsNullOrEmpty(value)) { bool isChecked; bool.TryParse(value, out isChecked); _document.CheckBox(_control.WatinAttribute).Checked = isChecked; WaitForAsyncPostBackToComplete(); } break; case "radiobutton": // if the value to set is empty, ignore it. if (!string.IsNullOrEmpty(value)) { _document.RadioButton((_control.WatinAttribute) && Find.ByValue(value)).Checked = true; WaitForAsyncPostBackToComplete(); ; } break; case "fileupload": _document.FileUpload(_control.WatinAttribute).Set(value); WaitForAsyncPostBackToComplete(); break; default: throw new NotImplementedException("The control type has not been implemented in Stax.Controller.Watin SetValue()"); } _document = BrowserController.DomContainer; }
public static void SetAlternateUser(string userName, string password, string domain) { // thread safe singleton code lock (threadSafeLock) { if (_ie == null) { StartIE(); } _ie.Close(); _ie = null; // fill the NetworkCredeitials object that we use for impersonation if (string.IsNullOrEmpty(domain)) { alternateUserCredentials = new NetworkCredential(userName, password); } else { alternateUserCredentials = new NetworkCredential(userName, password, domain); } // Prepare to launch ProcessStartInfo psi = new ProcessStartInfo(); psi.UserName = userName; psi.Password = SecurePassword(password); if (!string.IsNullOrEmpty(domain)) { psi.Domain = domain; } psi.UseShellExecute = false; psi.LoadUserProfile = true; psi.FileName = "c:\\Program Files\\Internet Explorer\\iexplore.exe"; psi.Arguments = "about:blank"; // launch Process proc = new Process(); proc.StartInfo = psi; proc.Start(); // Time to become an imposter hToken = IntPtr.Zero; hTokenDuplicate = IntPtr.Zero; if (Win32.LogonUser(alternateUserCredentials.UserName, alternateUserCredentials.Domain, alternateUserCredentials.Password, 2 /*LOGON32_LOGON_INTERACTIVE*/, 0 /*LOGON32_PROVIDER_DEFAULT*/, out hToken)) { if (Win32.DuplicateToken(hToken, 2, out hTokenDuplicate)) { windowsIdentity = new WindowsIdentity(hTokenDuplicate); impersonationContext = windowsIdentity.Impersonate(); //_ie = new IE(); System.Threading.Thread.Sleep(1000); _ie = IE.AttachToIE(Find.ByUrl("about:blank")); _document = _ie.DomContainer; InjectJQueryAjaxMonitor(); } } } }
public static bool DoesValueExist(string controlString, String value) { _control = new WatinControlStringHandler(controlString); if (_control.WaitForComplete) { _ie.WaitForComplete(); } WaitForAsyncPostBackToComplete(); SetDocument(); bool returnValue = false; switch (_control.ControlType) { case "select": if (_document.SelectList(_control.WatinAttribute).Option(value).Exists) { returnValue = true; } else { // Give a guy a second chance System.Threading.Thread.Sleep(500); returnValue = _document.SelectList(_control.WatinAttribute).Option(value).Exists; } break; default: throw new NotImplementedException( "The control type has not been implemented in Stax.Controller.Watin.DoesValueExist"); } _document = BrowserController.DomContainer; return returnValue; }
public static void PositionMousePointerInMiddleOfElement(Element button, Document ie) { var left = Position(button, "Left"); var width = int.Parse(button.GetAttributeValue("clientWidth")); var top = Position(button, "Top"); var height = int.Parse(button.GetAttributeValue("clientHeight")); var window = (IHTMLWindow3)((IEDocument)ie.NativeDocument).HtmlDocument.parentWindow; left = left + window.screenLeft; top = top + window.screenTop; var currentPt = new System.Drawing.Point(left + (width / 2), top + (height / 2)); System.Windows.Forms.Cursor.Position = currentPt; }
public cDocument(Document baseObject) : base(baseObject) { obj = baseObject; }
/// <summary> /// Dumps the elements with HTML source to <see cref="DebugLogWriter"/> /// </summary> /// <param name="document">The document.</param> public static void DumpElementsWithHtmlSource(Document document) { DumpElementsWithHtmlSource(document, new DebugLogWriter()); }
private static IHTMLElementCollection elementCollection(Document document) { return document.HtmlDocument.all; }
/// <summary> /// Dumps frame info. /// </summary> /// <param name="document">The document.</param> /// <param name="logWriter">The log writer.</param> public static void DumpFrames(Document document, ILogWriter logWriter) { FrameCollection frames = document.Frames; logWriter.LogAction("There are " + frames.Length.ToString() + " Frames"); int index = 0; foreach (Frame frame in frames) { logWriter.LogAction("Frame index: " + index.ToString()); logWriter.LogAction(" name: " + frame.Name); logWriter.LogAction(" scr: " + frame.Url); index++; } }
//я обрабатываю change но почему то click не вызывает change, по этому симулирую его private void SimulateClick(Document browser, string selector, CheckBox checkbox) { checkbox.Click(); browser.Eval(String.Format("$('{0}').change()", String.Format("{0} input[name=status]", selector))); }
/// <summary> /// Dumps frame info to <see cref="DebugLogWriter"/> /// </summary> /// <param name="document">The document.</param> public static void DumpFrames(Document document) { DumpFrames(document, new DebugLogWriter()); }
public CustomNativeElement(INativeElement inner, Document doc) : base(inner) { _doc = doc; }
internal void InitializePage(Document document) { InitializeControl(new WatElement(document)); }