|
19 | 19 | using System;
|
20 | 20 | using System.Collections.Generic;
|
21 | 21 | using System.Collections.ObjectModel;
|
| 22 | +using OpenQA.Selenium.Internal; |
22 | 23 |
|
23 | 24 | namespace OpenQA.Selenium
|
24 | 25 | {
|
25 | 26 | /// <summary>
|
26 | 27 | /// Provides a representation of an element's shadow root.
|
27 | 28 | /// </summary>
|
28 |
| - public class ShadowRoot : ISearchContext, IWrapsDriver |
| 29 | + public class ShadowRoot : ISearchContext, IWrapsDriver, IWebDriverObjectReference |
29 | 30 | {
|
30 | 31 | /// <summary>
|
31 | 32 | /// The property name that represents an element shadow root in the wire protocol.
|
@@ -54,6 +55,29 @@ public IWebDriver WrappedDriver
|
54 | 55 | get { return this.driver; }
|
55 | 56 | }
|
56 | 57 |
|
| 58 | + /// <summary> |
| 59 | + /// Gets the internal ID for this ShadowRoot. |
| 60 | + /// </summary> |
| 61 | + string IWebDriverObjectReference.ObjectReferenceId |
| 62 | + { |
| 63 | + get { return this.shadowRootId; } |
| 64 | + } |
| 65 | + |
| 66 | + internal static bool ContainsShadowRootReference(Dictionary<string, object> shadowRootDictionary) |
| 67 | + { |
| 68 | + if (shadowRootDictionary == null) |
| 69 | + { |
| 70 | + throw new ArgumentNullException(nameof(shadowRootDictionary), "The dictionary containing the shadow root reference cannot be null"); |
| 71 | + } |
| 72 | + |
| 73 | + return shadowRootDictionary.ContainsKey(ShadowRootReferencePropertyName); |
| 74 | + } |
| 75 | + |
| 76 | + internal static ShadowRoot FromDictionary(WebDriver driver, Dictionary<string, object> shadowRootDictionary) |
| 77 | + { |
| 78 | + return new ShadowRoot(driver, shadowRootDictionary[ShadowRoot.ShadowRootReferencePropertyName].ToString()); |
| 79 | + } |
| 80 | + |
57 | 81 | /// <summary>
|
58 | 82 | /// Finds the first <see cref="IWebElement"/> using the given method.
|
59 | 83 | /// </summary>
|
@@ -96,5 +120,12 @@ public ReadOnlyCollection<IWebElement> FindElements(By by)
|
96 | 120 | Response commandResponse = this.driver.InternalExecute(DriverCommand.FindShadowChildElements, parameters);
|
97 | 121 | return this.driver.GetElementsFromResponse(commandResponse);
|
98 | 122 | }
|
| 123 | + |
| 124 | + Dictionary<string, object> IWebDriverObjectReference.ToDictionary() |
| 125 | + { |
| 126 | + Dictionary<string, object> shadowRootDictionary = new Dictionary<string, object>(); |
| 127 | + shadowRootDictionary.Add(ShadowRootReferencePropertyName, this.shadowRootId); |
| 128 | + return shadowRootDictionary; |
| 129 | + } |
99 | 130 | }
|
100 | 131 | }
|
0 commit comments