Skip to content

Commit

Permalink
Allow extension of RemoteWebElement for caching properties
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Evans <james.h.evans.jr@gmail.com>
  • Loading branch information
mgkeeley authored and jimevans committed Jun 23, 2018
1 parent d31bfd3 commit c6686b3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
10 changes: 10 additions & 0 deletions dotnet/src/webdriver/Remote/RemoteWebDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,16 @@ protected virtual RemoteWebElement CreateElement(string elementId)
return toReturn;
}

/// <summary>
/// Creates a <see cref="RemoteWebElement"/> with the specified ID and element attributes.
/// </summary>
/// <param name="elementId">The ID of this element.</param>
/// <param name="elementDictionary">The attributes for this element.</param>
/// <returns>A <see cref="RemoteWebElement"/> with the specified ID.</returns>
protected virtual RemoteWebElement CreateElement(string id, Dictionary<string, object> elementDictionary) {
return CreateElement(id);
}

/// <summary>
/// Executes JavaScript in the context of the currently selected frame or window using a specific command.
/// </summary>
Expand Down
77 changes: 38 additions & 39 deletions dotnet/src/webdriver/Remote/RemoteWebElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public IWebDriver WrappedDriver
/// "input" for an element specified by the HTML markup &lt;input name="foo" /&gt;.
/// </remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public string TagName
public virtual string TagName
{
get
{
Expand All @@ -92,7 +92,7 @@ public string TagName
/// and with other whitespace collapsed.
/// </summary>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public string Text
public virtual string Text
{
get
{
Expand All @@ -109,7 +109,7 @@ public string Text
/// <remarks>The <see cref="Enabled"/> property will generally
/// return <see langword="true"/> for everything except explicitly disabled input elements.</remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public bool Enabled
public virtual bool Enabled
{
get
{
Expand All @@ -126,7 +126,7 @@ public bool Enabled
/// <remarks>This operation only applies to input elements such as checkboxes,
/// options in a select element and radio buttons.</remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public bool Selected
public virtual bool Selected
{
get
{
Expand All @@ -142,7 +142,7 @@ public bool Selected
/// of this element relative to the upper-left corner of the page.
/// </summary>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public Point Location
public virtual Point Location
{
get
{
Expand All @@ -166,7 +166,7 @@ public Point Location
/// Gets a <see cref="Size"/> object containing the height and width of this element.
/// </summary>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public Size Size
public virtual Size Size
{
get
{
Expand All @@ -193,7 +193,7 @@ public Size Size
/// of having to parse an element's "style" attribute to determine
/// visibility of an element.</remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public bool Displayed
public virtual bool Displayed
{
get
{
Expand All @@ -219,7 +219,7 @@ public bool Displayed
/// <summary>
/// Gets the point where the element would be when scrolled into view.
/// </summary>
public Point LocationOnScreenOnceScrolledIntoView
public virtual Point LocationOnScreenOnceScrolledIntoView
{
get
{
Expand Down Expand Up @@ -248,7 +248,7 @@ public Point LocationOnScreenOnceScrolledIntoView
/// Gets the coordinates identifying the location of this element using
/// various frames of reference.
/// </summary>
public ICoordinates Coordinates
public virtual ICoordinates Coordinates
{
get { return new RemoteCoordinates(this); }
}
Expand Down Expand Up @@ -283,7 +283,7 @@ protected string Id
/// method will clear the value. It has no effect on other elements. Text entry elements
/// are defined as elements with INPUT or TEXTAREA tags.</remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public void Clear()
public virtual void Clear()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", this.elementId);
Expand All @@ -301,7 +301,7 @@ public void Clear()
/// <exception cref="InvalidElementStateException">Thrown when the target element is not enabled.</exception>
/// <exception cref="ElementNotVisibleException">Thrown when the target element is not visible.</exception>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public void SendKeys(string text)
public virtual void SendKeys(string text)
{
if (text == null)
{
Expand Down Expand Up @@ -342,7 +342,7 @@ public void SendKeys(string text)
/// page to change, then this method will attempt to block until the new page
/// is loaded.</remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public void Submit()
public virtual void Submit()
{
if (this.driver.IsSpecificationCompliant)
{
Expand Down Expand Up @@ -382,7 +382,7 @@ public void Submit()
/// <exception cref="InvalidElementStateException">Thrown when the target element is not enabled.</exception>
/// <exception cref="ElementNotVisibleException">Thrown when the target element is not visible.</exception>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public void Click()
public virtual void Click()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", this.elementId);
Expand Down Expand Up @@ -423,7 +423,7 @@ public void Click()
/// </list>
/// </remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public string GetAttribute(string attributeName)
public virtual string GetAttribute(string attributeName)
{
Response commandResponse = null;
string attributeValue = string.Empty;
Expand Down Expand Up @@ -467,7 +467,7 @@ public string GetAttribute(string attributeName)
/// <returns>The JavaScript property's current value. Returns a <see langword="null"/> if the
/// value is not set or the property does not exist.</returns>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public string GetProperty(string propertyName)
public virtual string GetProperty(string propertyName)
{
string propertyValue = string.Empty;
Dictionary<string, object> parameters = new Dictionary<string, object>();
Expand Down Expand Up @@ -498,7 +498,7 @@ public string GetProperty(string propertyName)
/// "background-color" property set as "green" in the HTML source, will
/// return "#008000" for its value.</remarks>
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
public string GetCssValue(string propertyName)
public virtual string GetCssValue(string propertyName)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", this.Id);
Expand All @@ -522,7 +522,7 @@ public string GetCssValue(string propertyName)
/// <param name="by">The locating mechanism to use.</param>
/// <returns>A <see cref="ReadOnlyCollection{T}"/> of all <see cref="IWebElement">WebElements</see>
/// matching the current criteria, or an empty list if nothing matches.</returns>
public ReadOnlyCollection<IWebElement> FindElements(By by)
public virtual ReadOnlyCollection<IWebElement> FindElements(By by)
{
if (by == null)
{
Expand All @@ -538,7 +538,7 @@ public ReadOnlyCollection<IWebElement> FindElements(By by)
/// <param name="by">The locating mechanism to use.</param>
/// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns>
/// <exception cref="NoSuchElementException">If no element matches the criteria.</exception>
public IWebElement FindElement(By by)
public virtual IWebElement FindElement(By by)
{
if (by == null)
{
Expand All @@ -559,7 +559,7 @@ public IWebElement FindElement(By by)
/// IWebElement elem = driver.FindElementByLinkText("linktext")
/// </code>
/// </example>
public IWebElement FindElementByLinkText(string linkText)
public virtual IWebElement FindElementByLinkText(string linkText)
{
return this.FindElement("link text", linkText);
}
Expand All @@ -575,7 +575,7 @@ public IWebElement FindElementByLinkText(string linkText)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByLinkText("linktext")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
public virtual ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
{
return this.FindElements("link text", linkText);
}
Expand All @@ -591,7 +591,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
/// IWebElement elem = driver.FindElementById("id")
/// </code>
/// </example>
public IWebElement FindElementById(string id)
public virtual IWebElement FindElementById(string id)
{
if (this.driver.IsSpecificationCompliant)
{
Expand All @@ -612,7 +612,7 @@ public IWebElement FindElementById(string id)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsById("id")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsById(string id)
public virtual ReadOnlyCollection<IWebElement> FindElementsById(string id)
{
if (this.driver.IsSpecificationCompliant)
{
Expand All @@ -633,7 +633,7 @@ public ReadOnlyCollection<IWebElement> FindElementsById(string id)
/// elem = driver.FindElementsByName("name")
/// </code>
/// </example>
public IWebElement FindElementByName(string name)
public virtual IWebElement FindElementByName(string name)
{
// Element finding mechanism is not allowed by the W3C WebDriver
// specification, but rather should be implemented as a function
Expand All @@ -660,7 +660,7 @@ public IWebElement FindElementByName(string name)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByName("name")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsByName(string name)
public virtual ReadOnlyCollection<IWebElement> FindElementsByName(string name)
{
// Element finding mechanism is not allowed by the W3C WebDriver
// specification, but rather should be implemented as a function
Expand All @@ -687,7 +687,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByName(string name)
/// IWebElement elem = driver.FindElementsByTagName("tag")
/// </code>
/// </example>
public IWebElement FindElementByTagName(string tagName)
public virtual IWebElement FindElementByTagName(string tagName)
{
// Element finding mechanism is not allowed by the W3C WebDriver
// specification, but rather should be implemented as a function
Expand All @@ -714,7 +714,7 @@ public IWebElement FindElementByTagName(string tagName)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByTagName("tag")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)
public virtual ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)
{
// Element finding mechanism is not allowed by the W3C WebDriver
// specification, but rather should be implemented as a function
Expand All @@ -741,7 +741,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)
/// IWebElement elem = driver.FindElementByClassName("classname")
/// </code>
/// </example>
public IWebElement FindElementByClassName(string className)
public virtual IWebElement FindElementByClassName(string className)
{
// Element finding mechanism is not allowed by the W3C WebDriver
// specification, but rather should be implemented as a function
Expand All @@ -768,7 +768,7 @@ public IWebElement FindElementByClassName(string className)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByClassName("classname")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
public virtual ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
{
// Element finding mechanism is not allowed by the W3C WebDriver
// specification, but rather should be implemented as a function
Expand All @@ -795,7 +795,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
/// IWebElement elem = driver.FindElementsByXPath("//table/tbody/tr/td/a");
/// </code>
/// </example>
public IWebElement FindElementByXPath(string xpath)
public virtual IWebElement FindElementByXPath(string xpath)
{
return this.FindElement("xpath", xpath);
}
Expand All @@ -811,7 +811,7 @@ public IWebElement FindElementByXPath(string xpath)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByXpath("//tr/td/a")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)
public virtual ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)
{
return this.FindElements("xpath", xpath);
}
Expand All @@ -827,7 +827,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)
/// IWebElement elem = driver.FindElementsByPartialLinkText("partOfLink")
/// </code>
/// </example>
public IWebElement FindElementByPartialLinkText(string partialLinkText)
public virtual IWebElement FindElementByPartialLinkText(string partialLinkText)
{
return this.FindElement("partial link text", partialLinkText);
}
Expand All @@ -843,7 +843,7 @@ public IWebElement FindElementByPartialLinkText(string partialLinkText)
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByPartialLinkText("partOfTheLink")
/// </code>
/// </example>
public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText)
public virtual ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText)
{
return this.FindElements("partial link text", partialLinkText);
}
Expand All @@ -853,7 +853,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string part
/// </summary>
/// <param name="cssSelector">The id to match.</param>
/// <returns>The first <see cref="IWebElement"/> matching the criteria.</returns>
public IWebElement FindElementByCssSelector(string cssSelector)
public virtual IWebElement FindElementByCssSelector(string cssSelector)
{
return this.FindElement("css selector", cssSelector);
}
Expand All @@ -864,7 +864,7 @@ public IWebElement FindElementByCssSelector(string cssSelector)
/// <param name="cssSelector">The CSS selector to match.</param>
/// <returns>A <see cref="ReadOnlyCollection{T}"/> containing all
/// <see cref="IWebElement">IWebElements</see> matching the criteria.</returns>
public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector)
public virtual ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector)
{
return this.FindElements("css selector", cssSelector);
}
Expand All @@ -873,7 +873,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelec
/// Gets a <see cref="Screenshot"/> object representing the image of this element on the screen.
/// </summary>
/// <returns>A <see cref="Screenshot"/> object containing the image.</returns>
public Screenshot GetScreenshot()
public virtual Screenshot GetScreenshot()
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", this.elementId);
Expand Down Expand Up @@ -963,7 +963,7 @@ Dictionary<string, object> IWebElementReference.ToDictionary()
/// <param name="mechanism">The mechanism by which to find the element.</param>
/// <param name="value">The value to use to search for the element.</param>
/// <returns>The first <see cref="IWebElement"/> matching the given criteria.</returns>
protected IWebElement FindElement(string mechanism, string value)
protected virtual IWebElement FindElement(string mechanism, string value)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", this.elementId);
Expand All @@ -979,8 +979,7 @@ protected IWebElement FindElement(string mechanism, string value)
/// <param name="mechanism">The mechanism by which to find the elements.</param>
/// <param name="value">The value to use to search for the elements.</param>
/// <returns>A collection of all of the <see cref="IWebElement">IWebElements</see> matching the given criteria.</returns>
protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value)
{
protected virtual ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value) {
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("id", this.elementId);
parameters.Add("using", mechanism);
Expand All @@ -995,7 +994,7 @@ protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string
/// <param name="commandToExecute">The <see cref="DriverCommand"/> to execute against this element.</param>
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing names and values of the parameters for the command.</param>
/// <returns>The <see cref="Response"/> object containing the result of the command execution.</returns>
protected Response Execute(string commandToExecute, Dictionary<string, object> parameters)
protected virtual Response Execute(string commandToExecute, Dictionary<string, object> parameters)
{
return this.driver.InternalExecute(commandToExecute, parameters);
}
Expand Down

0 comments on commit c6686b3

Please sign in to comment.