IOS Element does not contain a definition for Text

I am trying to perform an assertion using C# that some text is populated in a specific field
var element= (_IOSdriver.FindElementsByAccessibilityId(“AddressCC”));
if (!string.IsNullOrEmpty(element.Text) && element.Text == “123 Main Street”);

I see this issue:
‘IReadOnlyCollection’ does not contain a definition for ‘Text’ and no accessible extension method ‘Text’ accepting a first argument of type ‘IReadOnlyCollection’ could be found (are you missing a using directive or an assembly reference?)

Any help would be appreciated

The FindElementsByAccessibilityId is returning a IReadOnlyCollection type and you are trying to call the .Text method on a collection. Probably need to iterate through the collection before applying .Text method to each/one special element. If there is just one element in the collection just pop it (or whatever) and apply .Text. If there are multiple elements in the collection, you may need to iterate through them and decide which one to use.

Disclaimer: Not a C# coder

I am trying to see if that text exists on the page if it does than it should pass. Is there a way to write an assertion to do that?

I’m sure there is. Here is a tutorial on Appium with C#. I hope it helps:

Thanks but this is setup I am passed that point. Selenium has some easier way to work with text so does Android not so much for IOS.

I disagree, but that’s fine. I will say that if you get a collection of elements from Android you still won’t be able to use a .Text method on it. That is OS agnostic.

Espresso can be used with Android.

So can uiautomator2.

Espresso is better at finding text than anything IOS has.

you tried predicate strings with iOS to find text? bet not!

when I use FindElementByIosNsPredicate instead of AccessibilityId I get Appium Driver does not contain a definition for FindElementByIosNsPredicate but If I open and use Appium inspector I can see that AddressCC is showing the 123 Main Street as its value just not sure how to put that into a Assertion?

Cause predicate is not what you thinking.

https://appium.io/docs/en/writing-running-appium/ios/ios-predicate/

Thanks Aleksei
I have seen this and they have decent Java and Ruby examples but after trying to edit these to work for C# they no longer work as they should.
// java
appiumDriver.findElementsByIosNsPredicate(“isWDVisible == 1”);
appiumDriver does not work so I change it to _IOSdriver and the findElementsByIosNsPredicate no longer works.

it should work. not clear what it your example.
e.g. to find element that contains some text:

// Java
MobileBy.iOSNsPredicateString("label CONTAINS[cd] 'search_text'")

// depending on your app iOS code text can be instead of ‘label’ in ‘name’ or ‘value’

hmm…I will keep trying I tried this but it has an issue with By not contain an issue for Displayed
var element = MobileBy.IosNSPredicate(“value==(‘123 Main Street’)”);
bool isDisplayed = element.Displayed;

I did create this which will work for one of my tests.
public void VerifyAddressPresentOrNot()
{
IWebElement AddressText = _IOSdriver.FindElementByAccessibilityId(“AddressCC”);
string ExpText = “123 Main Street”;
string ActText = AddressText.Text;
if (ExpText.Equals(ActText))
{
Assert.AreEqual(ExpText, ActText);
Console.WriteLine(“Address verified Successfully”);
}
else
{
Console.WriteLine(“Address Verification Failed”);
}
}