From 5d9df88642c1d92cb04d1b1236142f1d0b1679f9 Mon Sep 17 00:00:00 2001 From: Dor-bl Date: Thu, 21 Sep 2023 18:06:42 +0300 Subject: [PATCH] fix: Add new methods for extended element finding in AppiumElement --- src/Appium.Net/Appium/AppiumElement.cs | 24 ++++++++++++++++++++++-- test/integration/Android/ElementTest.cs | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Appium.Net/Appium/AppiumElement.cs b/src/Appium.Net/Appium/AppiumElement.cs index b2142c1e..da387cc7 100644 --- a/src/Appium.Net/Appium/AppiumElement.cs +++ b/src/Appium.Net/Appium/AppiumElement.cs @@ -220,10 +220,30 @@ AppiumElement IFindsByFluentSelector.FindElement(string by, strin IReadOnlyCollection IFindsByFluentSelector.FindElements(string selector, string value) { - return ConvertToExtendedWebElementCollection(base.FindElements(selector, value)); + return ConvertToAppiumElementCollection(base.FindElements(selector, value)); } - internal static ReadOnlyCollection ConvertToExtendedWebElementCollection(IEnumerable collection) + /// + /// Finds the first element that matches the specified selector and returns it as an . + /// + /// The selector used to locate the element. + /// The first that matches the selector. + public new AppiumElement FindElement(By by) + { + return (AppiumElement)base.FindElement(by); + } + + /// + /// Finds all elements that match the specified selector and returns them as a read-only collection of . + /// + /// The selector used to locate the elements. + /// A read-only collection of objects matching the selector. + public new ReadOnlyCollection FindElements(By by) + { + return ConvertToAppiumElementCollection(base.FindElements(by)); + } + + internal static ReadOnlyCollection ConvertToAppiumElementCollection(IEnumerable collection) { return collection.Cast().ToList().AsReadOnly(); } diff --git a/test/integration/Android/ElementTest.cs b/test/integration/Android/ElementTest.cs index 6def9932..c331b10e 100644 --- a/test/integration/Android/ElementTest.cs +++ b/test/integration/Android/ElementTest.cs @@ -126,6 +126,22 @@ public void ScrollingToSubElementUsingBuilder() Assert.NotNull(radioGroup.Location); } + [Test] + public void FindAppiumElementUsingNestedElement() + { + var myElement = _driver.FindElement(MobileBy.Id("android:id/content")); + AppiumElement nestedElement = myElement.FindElement(By.Id("android:id/text1")); + Assert.NotNull(nestedElement); + } + + [Test] + public void FindAppiumElementsListUsingNestedElement() + { + var myElement = _driver.FindElement(MobileBy.Id("android:id/content")); + IList myDerivedElements = myElement.FindElements(By.Id("android:id/text1")); + Assert.AreNotEqual(myDerivedElements.Count,0); + } + [OneTimeTearDown] public void AfterAll() {