Skip to content

Commit c6686b3

Browse files
mgkeeleyjimevans
authored andcommitted
Allow extension of RemoteWebElement for caching properties
Signed-off-by: Jim Evans <[email protected]>
1 parent d31bfd3 commit c6686b3

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
lines changed

dotnet/src/webdriver/Remote/RemoteWebDriver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,16 @@ protected virtual RemoteWebElement CreateElement(string elementId)
12071207
return toReturn;
12081208
}
12091209

1210+
/// <summary>
1211+
/// Creates a <see cref="RemoteWebElement"/> with the specified ID and element attributes.
1212+
/// </summary>
1213+
/// <param name="elementId">The ID of this element.</param>
1214+
/// <param name="elementDictionary">The attributes for this element.</param>
1215+
/// <returns>A <see cref="RemoteWebElement"/> with the specified ID.</returns>
1216+
protected virtual RemoteWebElement CreateElement(string id, Dictionary<string, object> elementDictionary) {
1217+
return CreateElement(id);
1218+
}
1219+
12101220
/// <summary>
12111221
/// Executes JavaScript in the context of the currently selected frame or window using a specific command.
12121222
/// </summary>

dotnet/src/webdriver/Remote/RemoteWebElement.cs

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public IWebDriver WrappedDriver
7676
/// "input" for an element specified by the HTML markup &lt;input name="foo" /&gt;.
7777
/// </remarks>
7878
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
79-
public string TagName
79+
public virtual string TagName
8080
{
8181
get
8282
{
@@ -92,7 +92,7 @@ public string TagName
9292
/// and with other whitespace collapsed.
9393
/// </summary>
9494
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
95-
public string Text
95+
public virtual string Text
9696
{
9797
get
9898
{
@@ -109,7 +109,7 @@ public string Text
109109
/// <remarks>The <see cref="Enabled"/> property will generally
110110
/// return <see langword="true"/> for everything except explicitly disabled input elements.</remarks>
111111
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
112-
public bool Enabled
112+
public virtual bool Enabled
113113
{
114114
get
115115
{
@@ -126,7 +126,7 @@ public bool Enabled
126126
/// <remarks>This operation only applies to input elements such as checkboxes,
127127
/// options in a select element and radio buttons.</remarks>
128128
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
129-
public bool Selected
129+
public virtual bool Selected
130130
{
131131
get
132132
{
@@ -142,7 +142,7 @@ public bool Selected
142142
/// of this element relative to the upper-left corner of the page.
143143
/// </summary>
144144
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
145-
public Point Location
145+
public virtual Point Location
146146
{
147147
get
148148
{
@@ -166,7 +166,7 @@ public Point Location
166166
/// Gets a <see cref="Size"/> object containing the height and width of this element.
167167
/// </summary>
168168
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
169-
public Size Size
169+
public virtual Size Size
170170
{
171171
get
172172
{
@@ -193,7 +193,7 @@ public Size Size
193193
/// of having to parse an element's "style" attribute to determine
194194
/// visibility of an element.</remarks>
195195
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
196-
public bool Displayed
196+
public virtual bool Displayed
197197
{
198198
get
199199
{
@@ -219,7 +219,7 @@ public bool Displayed
219219
/// <summary>
220220
/// Gets the point where the element would be when scrolled into view.
221221
/// </summary>
222-
public Point LocationOnScreenOnceScrolledIntoView
222+
public virtual Point LocationOnScreenOnceScrolledIntoView
223223
{
224224
get
225225
{
@@ -248,7 +248,7 @@ public Point LocationOnScreenOnceScrolledIntoView
248248
/// Gets the coordinates identifying the location of this element using
249249
/// various frames of reference.
250250
/// </summary>
251-
public ICoordinates Coordinates
251+
public virtual ICoordinates Coordinates
252252
{
253253
get { return new RemoteCoordinates(this); }
254254
}
@@ -283,7 +283,7 @@ protected string Id
283283
/// method will clear the value. It has no effect on other elements. Text entry elements
284284
/// are defined as elements with INPUT or TEXTAREA tags.</remarks>
285285
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
286-
public void Clear()
286+
public virtual void Clear()
287287
{
288288
Dictionary<string, object> parameters = new Dictionary<string, object>();
289289
parameters.Add("id", this.elementId);
@@ -301,7 +301,7 @@ public void Clear()
301301
/// <exception cref="InvalidElementStateException">Thrown when the target element is not enabled.</exception>
302302
/// <exception cref="ElementNotVisibleException">Thrown when the target element is not visible.</exception>
303303
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
304-
public void SendKeys(string text)
304+
public virtual void SendKeys(string text)
305305
{
306306
if (text == null)
307307
{
@@ -342,7 +342,7 @@ public void SendKeys(string text)
342342
/// page to change, then this method will attempt to block until the new page
343343
/// is loaded.</remarks>
344344
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
345-
public void Submit()
345+
public virtual void Submit()
346346
{
347347
if (this.driver.IsSpecificationCompliant)
348348
{
@@ -382,7 +382,7 @@ public void Submit()
382382
/// <exception cref="InvalidElementStateException">Thrown when the target element is not enabled.</exception>
383383
/// <exception cref="ElementNotVisibleException">Thrown when the target element is not visible.</exception>
384384
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
385-
public void Click()
385+
public virtual void Click()
386386
{
387387
Dictionary<string, object> parameters = new Dictionary<string, object>();
388388
parameters.Add("id", this.elementId);
@@ -423,7 +423,7 @@ public void Click()
423423
/// </list>
424424
/// </remarks>
425425
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
426-
public string GetAttribute(string attributeName)
426+
public virtual string GetAttribute(string attributeName)
427427
{
428428
Response commandResponse = null;
429429
string attributeValue = string.Empty;
@@ -467,7 +467,7 @@ public string GetAttribute(string attributeName)
467467
/// <returns>The JavaScript property's current value. Returns a <see langword="null"/> if the
468468
/// value is not set or the property does not exist.</returns>
469469
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
470-
public string GetProperty(string propertyName)
470+
public virtual string GetProperty(string propertyName)
471471
{
472472
string propertyValue = string.Empty;
473473
Dictionary<string, object> parameters = new Dictionary<string, object>();
@@ -498,7 +498,7 @@ public string GetProperty(string propertyName)
498498
/// "background-color" property set as "green" in the HTML source, will
499499
/// return "#008000" for its value.</remarks>
500500
/// <exception cref="StaleElementReferenceException">Thrown when the target element is no longer valid in the document DOM.</exception>
501-
public string GetCssValue(string propertyName)
501+
public virtual string GetCssValue(string propertyName)
502502
{
503503
Dictionary<string, object> parameters = new Dictionary<string, object>();
504504
parameters.Add("id", this.Id);
@@ -522,7 +522,7 @@ public string GetCssValue(string propertyName)
522522
/// <param name="by">The locating mechanism to use.</param>
523523
/// <returns>A <see cref="ReadOnlyCollection{T}"/> of all <see cref="IWebElement">WebElements</see>
524524
/// matching the current criteria, or an empty list if nothing matches.</returns>
525-
public ReadOnlyCollection<IWebElement> FindElements(By by)
525+
public virtual ReadOnlyCollection<IWebElement> FindElements(By by)
526526
{
527527
if (by == null)
528528
{
@@ -538,7 +538,7 @@ public ReadOnlyCollection<IWebElement> FindElements(By by)
538538
/// <param name="by">The locating mechanism to use.</param>
539539
/// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns>
540540
/// <exception cref="NoSuchElementException">If no element matches the criteria.</exception>
541-
public IWebElement FindElement(By by)
541+
public virtual IWebElement FindElement(By by)
542542
{
543543
if (by == null)
544544
{
@@ -559,7 +559,7 @@ public IWebElement FindElement(By by)
559559
/// IWebElement elem = driver.FindElementByLinkText("linktext")
560560
/// </code>
561561
/// </example>
562-
public IWebElement FindElementByLinkText(string linkText)
562+
public virtual IWebElement FindElementByLinkText(string linkText)
563563
{
564564
return this.FindElement("link text", linkText);
565565
}
@@ -575,7 +575,7 @@ public IWebElement FindElementByLinkText(string linkText)
575575
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByLinkText("linktext")
576576
/// </code>
577577
/// </example>
578-
public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
578+
public virtual ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
579579
{
580580
return this.FindElements("link text", linkText);
581581
}
@@ -591,7 +591,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByLinkText(string linkText)
591591
/// IWebElement elem = driver.FindElementById("id")
592592
/// </code>
593593
/// </example>
594-
public IWebElement FindElementById(string id)
594+
public virtual IWebElement FindElementById(string id)
595595
{
596596
if (this.driver.IsSpecificationCompliant)
597597
{
@@ -612,7 +612,7 @@ public IWebElement FindElementById(string id)
612612
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsById("id")
613613
/// </code>
614614
/// </example>
615-
public ReadOnlyCollection<IWebElement> FindElementsById(string id)
615+
public virtual ReadOnlyCollection<IWebElement> FindElementsById(string id)
616616
{
617617
if (this.driver.IsSpecificationCompliant)
618618
{
@@ -633,7 +633,7 @@ public ReadOnlyCollection<IWebElement> FindElementsById(string id)
633633
/// elem = driver.FindElementsByName("name")
634634
/// </code>
635635
/// </example>
636-
public IWebElement FindElementByName(string name)
636+
public virtual IWebElement FindElementByName(string name)
637637
{
638638
// Element finding mechanism is not allowed by the W3C WebDriver
639639
// specification, but rather should be implemented as a function
@@ -660,7 +660,7 @@ public IWebElement FindElementByName(string name)
660660
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByName("name")
661661
/// </code>
662662
/// </example>
663-
public ReadOnlyCollection<IWebElement> FindElementsByName(string name)
663+
public virtual ReadOnlyCollection<IWebElement> FindElementsByName(string name)
664664
{
665665
// Element finding mechanism is not allowed by the W3C WebDriver
666666
// specification, but rather should be implemented as a function
@@ -687,7 +687,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByName(string name)
687687
/// IWebElement elem = driver.FindElementsByTagName("tag")
688688
/// </code>
689689
/// </example>
690-
public IWebElement FindElementByTagName(string tagName)
690+
public virtual IWebElement FindElementByTagName(string tagName)
691691
{
692692
// Element finding mechanism is not allowed by the W3C WebDriver
693693
// specification, but rather should be implemented as a function
@@ -714,7 +714,7 @@ public IWebElement FindElementByTagName(string tagName)
714714
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByTagName("tag")
715715
/// </code>
716716
/// </example>
717-
public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)
717+
public virtual ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)
718718
{
719719
// Element finding mechanism is not allowed by the W3C WebDriver
720720
// specification, but rather should be implemented as a function
@@ -741,7 +741,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByTagName(string tagName)
741741
/// IWebElement elem = driver.FindElementByClassName("classname")
742742
/// </code>
743743
/// </example>
744-
public IWebElement FindElementByClassName(string className)
744+
public virtual IWebElement FindElementByClassName(string className)
745745
{
746746
// Element finding mechanism is not allowed by the W3C WebDriver
747747
// specification, but rather should be implemented as a function
@@ -768,7 +768,7 @@ public IWebElement FindElementByClassName(string className)
768768
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByClassName("classname")
769769
/// </code>
770770
/// </example>
771-
public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
771+
public virtual ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
772772
{
773773
// Element finding mechanism is not allowed by the W3C WebDriver
774774
// specification, but rather should be implemented as a function
@@ -795,7 +795,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByClassName(string className)
795795
/// IWebElement elem = driver.FindElementsByXPath("//table/tbody/tr/td/a");
796796
/// </code>
797797
/// </example>
798-
public IWebElement FindElementByXPath(string xpath)
798+
public virtual IWebElement FindElementByXPath(string xpath)
799799
{
800800
return this.FindElement("xpath", xpath);
801801
}
@@ -811,7 +811,7 @@ public IWebElement FindElementByXPath(string xpath)
811811
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByXpath("//tr/td/a")
812812
/// </code>
813813
/// </example>
814-
public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)
814+
public virtual ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)
815815
{
816816
return this.FindElements("xpath", xpath);
817817
}
@@ -827,7 +827,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByXPath(string xpath)
827827
/// IWebElement elem = driver.FindElementsByPartialLinkText("partOfLink")
828828
/// </code>
829829
/// </example>
830-
public IWebElement FindElementByPartialLinkText(string partialLinkText)
830+
public virtual IWebElement FindElementByPartialLinkText(string partialLinkText)
831831
{
832832
return this.FindElement("partial link text", partialLinkText);
833833
}
@@ -843,7 +843,7 @@ public IWebElement FindElementByPartialLinkText(string partialLinkText)
843843
/// ReadOnlyCollection<![CDATA[<IWebElement>]]> elem = driver.FindElementsByPartialLinkText("partOfTheLink")
844844
/// </code>
845845
/// </example>
846-
public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText)
846+
public virtual ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string partialLinkText)
847847
{
848848
return this.FindElements("partial link text", partialLinkText);
849849
}
@@ -853,7 +853,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByPartialLinkText(string part
853853
/// </summary>
854854
/// <param name="cssSelector">The id to match.</param>
855855
/// <returns>The first <see cref="IWebElement"/> matching the criteria.</returns>
856-
public IWebElement FindElementByCssSelector(string cssSelector)
856+
public virtual IWebElement FindElementByCssSelector(string cssSelector)
857857
{
858858
return this.FindElement("css selector", cssSelector);
859859
}
@@ -864,7 +864,7 @@ public IWebElement FindElementByCssSelector(string cssSelector)
864864
/// <param name="cssSelector">The CSS selector to match.</param>
865865
/// <returns>A <see cref="ReadOnlyCollection{T}"/> containing all
866866
/// <see cref="IWebElement">IWebElements</see> matching the criteria.</returns>
867-
public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector)
867+
public virtual ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelector)
868868
{
869869
return this.FindElements("css selector", cssSelector);
870870
}
@@ -873,7 +873,7 @@ public ReadOnlyCollection<IWebElement> FindElementsByCssSelector(string cssSelec
873873
/// Gets a <see cref="Screenshot"/> object representing the image of this element on the screen.
874874
/// </summary>
875875
/// <returns>A <see cref="Screenshot"/> object containing the image.</returns>
876-
public Screenshot GetScreenshot()
876+
public virtual Screenshot GetScreenshot()
877877
{
878878
Dictionary<string, object> parameters = new Dictionary<string, object>();
879879
parameters.Add("id", this.elementId);
@@ -963,7 +963,7 @@ Dictionary<string, object> IWebElementReference.ToDictionary()
963963
/// <param name="mechanism">The mechanism by which to find the element.</param>
964964
/// <param name="value">The value to use to search for the element.</param>
965965
/// <returns>The first <see cref="IWebElement"/> matching the given criteria.</returns>
966-
protected IWebElement FindElement(string mechanism, string value)
966+
protected virtual IWebElement FindElement(string mechanism, string value)
967967
{
968968
Dictionary<string, object> parameters = new Dictionary<string, object>();
969969
parameters.Add("id", this.elementId);
@@ -979,8 +979,7 @@ protected IWebElement FindElement(string mechanism, string value)
979979
/// <param name="mechanism">The mechanism by which to find the elements.</param>
980980
/// <param name="value">The value to use to search for the elements.</param>
981981
/// <returns>A collection of all of the <see cref="IWebElement">IWebElements</see> matching the given criteria.</returns>
982-
protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value)
983-
{
982+
protected virtual ReadOnlyCollection<IWebElement> FindElements(string mechanism, string value) {
984983
Dictionary<string, object> parameters = new Dictionary<string, object>();
985984
parameters.Add("id", this.elementId);
986985
parameters.Add("using", mechanism);
@@ -995,7 +994,7 @@ protected ReadOnlyCollection<IWebElement> FindElements(string mechanism, string
995994
/// <param name="commandToExecute">The <see cref="DriverCommand"/> to execute against this element.</param>
996995
/// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing names and values of the parameters for the command.</param>
997996
/// <returns>The <see cref="Response"/> object containing the result of the command execution.</returns>
998-
protected Response Execute(string commandToExecute, Dictionary<string, object> parameters)
997+
protected virtual Response Execute(string commandToExecute, Dictionary<string, object> parameters)
999998
{
1000999
return this.driver.InternalExecute(commandToExecute, parameters);
10011000
}

0 commit comments

Comments
 (0)