MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / WebElement

Class WebElement

dotnet/src/webdriver/WebElement.cs:32–745  ·  view source on GitHub ↗

A base class representing an HTML element on a page.

Source from the content-addressed store, hash-verified

30/// A base class representing an HTML element on a page.
31/// </summary>
32public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebDriverObjectReference, IEquatable<IWebElement>
33{
34 /// <summary>
35 /// The property name that represents a web element in the wire protocol.
36 /// </summary>
37 public const string ElementReferencePropertyName = "element-6066-11e4-a52e-4f735466cecf";
38
39 private readonly WebDriver driver;
40
41 /// <summary>
42 /// Initializes a new instance of the <see cref="WebElement"/> class.
43 /// </summary>
44 /// <param name="parentDriver">The <see cref="WebDriver"/> instance that is driving this element.</param>
45 /// <param name="id">The ID value provided to identify the element.</param>
46 /// <exception cref="ArgumentNullException">If <paramref name="parentDriver"/> or <paramref name="id"/> are <see langword="null"/>.</exception>
47 public WebElement(WebDriver parentDriver, string id)
48 {
49 ArgumentNullException.ThrowIfNull(parentDriver);
50 ArgumentNullException.ThrowIfNull(id);
51 this.driver = parentDriver;
52 this.Id = id;
53 }
54
55 /// <summary>
56 /// Gets the <see cref="IWebDriver"/> driving this element.
57 /// </summary>
58 public IWebDriver WrappedDriver => this.driver;
59
60 /// <summary>
61 /// Gets the tag name of this element.
62 /// </summary>
63 /// <remarks>
64 /// The <see cref="TagName"/> property returns the tag name of the
65 /// element, not the value of the name attribute. For example, it will return
66 /// "input" for an element specified by the HTML markup &lt;input name="foo" /&gt;.
67 /// </remarks>
68 /// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
69 public virtual string TagName
70 {
71 get
72 {
73 Dictionary<string, object> parameters = new Dictionary<string, object>();
74 parameters.Add("id", this.Id);
75
76 Response commandResponse = this.Execute(DriverCommand.GetElementTagName, parameters);
77
78 commandResponse.EnsureValueIsNotNull();
79 return commandResponse.Value.ToString()!;
80 }
81 }
82
83 /// <summary>
84 /// Gets the innerText of this element, without any leading or trailing whitespace,
85 /// and with other whitespace collapsed.
86 /// </summary>
87 /// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
88 public virtual string Text
89 {

Callers

nothing calls this directly

Calls 6

ExecuteMethod · 0.95
EnsureValueIsNotNullMethod · 0.80
AddMethod · 0.45
ToStringMethod · 0.45
ToDictionaryMethod · 0.45
ExecuteScriptMethod · 0.45

Tested by

no test coverage detected