/// <summary> /// Click the ASP.NET control element (usually a Button instance) directly and wait for the response /// when expectPostBack is true. /// </summary> /// <param name="control">The ASP.NET control to click on</param> /// <param name="expectPostBack">Whether to expect a server request from the click</param> /// <param name="samePage">Whether the PostBack stays on the same page with the same HTML element</param> /// <param name="expectedStatusCode">Expected StatusCode of the response</param> /// <param name="delay">Optional delay time in milliseconds before clicking the element</param> /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param> public static void Click(this ISelenium inst, Control control, bool expectPostBack = true, bool samePage = false, int expectedStatusCode = 200, int delay = 0, int pause = 0) { SeleniumExtensionBase.ClickID(inst, control.ClientID, expectRequest: expectPostBack, samePage: samePage, expectedStatusCode: expectedStatusCode, delay: delay, pause: pause); }
/// <summary> /// Click the ASP.NET control element (usually a Button instance) at the given path and wait for the response /// when expectPostBack is true. /// </summary> /// <param name="path">Member name path to the control starting at the main control</param> /// <param name="expectPostBack">Whether to expect a server request from the click</param> /// <param name="samePage">Whether the PostBack stays on the same page with the same HTML element</param> /// <param name="expectedStatusCode">Expected StatusCofe of the response</param> /// <param name="delay">Optional delay time in milliseconds before clicking the element</param> /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param> public static void Click(this ISelenium inst, string path, bool expectPostBack = true, bool samePage = false, int expectedStatusCode = 200, int delay = 0, int pause = 0) { var button = GetControl(inst, path); SeleniumExtensionBase.ClickID(inst, button.ClientID, expectRequest: expectPostBack, samePage: samePage, expectedStatusCode: expectedStatusCode, delay: delay, pause: pause); }
/// <summary> /// Click the HTML element (usually a Button) with the given id and /// index, don't wait for a response as expectRequest defaults to false for an SPA, /// but wait RequestTimeout seconds for the element to appear. /// </summary> /// <param id="id">HTML id attribute of the element to click on</param> /// <param name="index">Index of the element collection with that id, defaults to 0</param> /// <param name="expectRequest">Whether to expect a GET/POST request to the server from the click</param> /// <param name="samePage">Whether to expect a WebForms style PostBack to the same page with the same HTML element</param> /// <param name="awaitRemoved">Whether to wait for the HTML element to disappear (in an SPA)</param> /// <param name="expectedStatusCode">Expected StatusCofe of the response</param> /// <param name="delay">Optional delay time in milliseconds before clicking the element</param> /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param> /// <param name="wait">Explicit WebDriverWait in seconds for the element to appear</param> public void Click(string id, int index = 0, bool expectRequest = false, bool?samePage = null, bool?awaitRemoved = null, int expectedStatusCode = 200, int delay = 0, int pause = 0, int wait = 0) { var doAwaitRemoved = awaitRemoved ?? this.awaitRemovedDefault; var onSamePage = samePage ?? this.samePageDefault; SeleniumExtensionBase.ClickID(this, id, index, expectRequest: expectRequest, samePage: onSamePage, awaitRemoved: doAwaitRemoved, expectedStatusCode: expectedStatusCode, delay: delay, pause: pause, wait: (wait == 0) ? SeleniumExtensionBase.RequestTimeout : wait); }
/// <summary> /// Select the item with the given value from a ListControl and wait for the response /// when expectPostBack is true. /// </summary> /// <param name="path">Member name path to the control starting at the main control</param> /// <param name="value">value of the item to click on</param> /// <param name="expectPostBack">Whether to expect a server request from the click. Defaults to false</param> /// <param name="expectedStatusCode">Expected StatusCode of the response</param> /// <param name="delay">Optional delay time in milliseconds before clicking the element</param> /// <param name="pause">Optional pause time in milliseconds after IE claims DocumentComplete</param> public static void Select(this ISelenium inst, string path, string value, bool expectPostBack = false, int expectedStatusCode = 200, int delay = 0, int pause = 0) { var list = GetControl(inst, path) as ListControl; if (list == null) { throw new Exception(String.Format("ListControl at '{0}' not found", path)); } for (int idx = 0; idx <= list.Items.Count; idx++) { if (idx == list.Items.Count) { throw new Exception(String.Format("ListControl at '{0}': value '{1}' not found", path, value)); } else if (list.Items[idx].Value == value) { string itemID = String.Format("{0}_{1}", list.ClientID, idx); SeleniumExtensionBase.ClickID(inst, itemID, expectRequest: expectPostBack, samePage: !expectPostBack, expectedStatusCode: expectedStatusCode, delay: delay, pause: pause); break; } } }