// Attribute /// <summary> /// Asserts that the element has the specified attribute. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="name">The attribute name</param> /// <param name="because">A phrase explaining why the assertion is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public static async Task ShouldHaveAttributeAsync(this ElementHandle elementHandle, string name, string because = null) { if (!await elementHandle.HasAttributeAsync(name).ConfigureAwait(false)) { Throw.ShouldHaveAttribute(elementHandle, name, because); } }
/// <summary> /// Asserts that the element does not have the specified attribute. /// </summary> /// <param name="handle">An <see cref="ElementHandle"/></param> /// <param name="name">The attribute name</param> /// <param name="message">Optional failure message</param> public static async Task ShouldNotHaveAttributeAsync(this ElementHandle handle, string name, string message = null) { if (await handle.HasAttributeAsync(name).ConfigureAwait(false)) { Throw.ShouldNotHaveAttribute(handle, message); } }
// HasAttribute /// <summary> /// Indicates whether the element has the specified attribute or not. /// </summary> /// <param name="elementHandle">An <see cref="ElementHandle"/></param> /// <param name="name">The attribute name</param> /// <returns><c>true</c> if the element has the specified attribute</returns> /// <seealso href="https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute"/> public static bool HasAttribute(this ElementHandle elementHandle, string name) { return(elementHandle.HasAttributeAsync(name).Result()); }