public ExecuteScript ( string script ) : object | ||
script | string | The JavaScript code to execute. |
return | object |
/// <summary> /// Method for creating a cookie in the browser. /// </summary> /// <param name="cookie"><see cref="Cookie"/> that represents a cookie in the browser.</param> public void AddCookie(Cookie cookie) { ////wdAddCookie does not properly add cookies with expiration dates, ////thus cookies are not properly deleted. Use JavaScript execution, ////just like the Java implementation does. ////string cookieString = cookie.ToString(); ////WebDriverResult result = NativeDriverLibrary.Instance.AddCookie(driver.handle, cookieString); ////ResultHandler.VerifyResultCode(result, "Add Cookie"); StringBuilder sb = new StringBuilder(cookie.Name); sb.Append("="); sb.Append(cookie.Value); sb.Append("; "); if (!string.IsNullOrEmpty(cookie.Path)) { sb.Append("path="); sb.Append(cookie.Path); sb.Append("; "); } if (!string.IsNullOrEmpty(cookie.Domain)) { string domain = cookie.Domain; int colon = domain.IndexOf(":", StringComparison.OrdinalIgnoreCase); if (colon != -1) { domain = domain.Substring(0, colon); } sb.Append("domain="); sb.Append(domain); sb.Append("; "); } if (cookie.Expiry != null) { sb.Append("expires="); sb.Append(cookie.Expiry.Value.ToUniversalTime().ToString("ddd MM/dd/yyyy HH:mm:ss UTC", CultureInfo.InvariantCulture)); } driver.ExecuteScript("document.cookie = arguments[0]", sb.ToString()); }
/// <summary> /// Compares if two elements are equal. /// </summary> /// <param name="obj">Object to compare against.</param> /// <returns>A boolean if it is equal or not.</returns> public override bool Equals(object obj) { IWebElement other = obj as IWebElement; if (other == null) { return(false); } if (other is IWrapsElement) { other = ((IWrapsElement)obj).WrappedElement; } if (!(other is InternetExplorerWebElement)) { return(false); } bool result = (bool)driver.ExecuteScript("return arguments[0] === arguments[1];", this, other); return(result); }