public void SetGetValuesFromDOM() { // HtmlControl/Elements now have a generic SetValue/GetValue that allows developers // to set/get values directly from the DOM for any property on the control. Whether it is inherited, // readonly or an emitted attribute. // Get whether a checkbox is enabled or disabled. HtmlInputCheckBox cks = Find.ById <HtmlInputCheckBox>("checkbox1"); bool disabled = cks.GetValue <bool>("disabled"); // Disable it cks.SetValue <string>("disabled", "true"); Assert.IsTrue(cks.GetValue <bool>("disabled")); // Is it visible. IsVisible follows the CSS chain to determine if the // element is actually visible or not. An element is visible when // the CSS the display style is not 'none' and the visibility style // is not 'hidden'. Assert.IsTrue(cks.IsVisible()); // Get the color style HtmlSpan mySpan = Find.ById <HtmlSpan>("Warning"); HtmlStyle styleColor = mySpan.GetStyle("color"); string strColor = mySpan.GetStyleValue("color"); // Getting the computed style will follow the CSS chain and return the // style. HtmlStyle styleMargin = mySpan.GetComputedStyle("margin"); string strMargin = mySpan.GetComputedStyleValue("margin"); }
public void CommonHtmlControlMethodsProperties() { // All controls have a Click/MouseClick. The .Click invokes a click from the DOM, // the MouseClick(), moves the mouse to the controls and clicks it. // // CLICKING // Find.ById <HtmlInputButton>("button1").Click(); ActiveBrowser.Refresh(); Find.ById <HtmlInputButton>("button1").MouseClick(); // You can capture any element on the page using the .Capture() Find.ById <HtmlInputImage>("image1").Capture("myfile"); // Will be stored to the Log.LogLocation // // CHECKING // // Check a checkbox and invoke the onclick event. HtmlInputCheckBox ck = Find.ById <HtmlInputCheckBox>("checkbox1"); if (ActiveBrowser.BrowserType == BrowserType.Safari) { // Unfortunately the way Safari behaves is different then the other browsers. ck.Check(true, false); } else { ck.Check(true, true); } // Query the checked state Assert.IsTrue(ck.Checked); // You can also simply set the value without invoking the clicked event. ck.Checked = false; Assert.IsFalse(ck.Checked); // Get whether a checkbox is enabled or disabled. HtmlInputCheckBox cks = Find.ById <HtmlInputCheckBox>("checkbox1"); bool disabled = cks.GetValue <bool>("disabled"); // Disable it cks.SetValue <string>("disabled", "true"); Assert.IsTrue(cks.GetValue <bool>("disabled")); // Is it visible Assert.IsTrue(cks.IsVisible()); // When the contents of a div element are larger than the declared // width or height of element it automatically adds scroll bars. // When that happens we can scroll the contents of the div element. // The value represents the offset in pixels to scroll the contents. HtmlDiv infoDiv = Find.ById <HtmlDiv>("AutoInfo"); infoDiv.ScrollTop = 50; infoDiv.ScrollLeft = 75; // // SELECTING // HtmlSelect select = Find.ById <HtmlSelect>("color_product"); Assert.IsTrue(select.SelectedOption.Value.Equals("Blue")); Assert.IsTrue(select.SelectedOption.Text.Equals("Color : Blue")); select.SelectByIndex(1); Assert.IsTrue(select.SelectedOption.Text.Equals("Color : Green")); // // SET TEXT // Find.ById <HtmlTextArea>("textarea1").Text = "NEW TEXT"; // Access common methods HtmlAnchor link = Find.ByAttributes <HtmlAnchor>("href=~google"); Assert.IsTrue(link.Attributes.Count == 3); Assert.IsTrue(link.BaseElement.TextContent.Trim().Equals("Link")); // Invoke any events on the control link.InvokeEvent(ScriptEventType.OnFocus); }