-4

I get exception after pressing click() for "FindElemebtByID". I get this exception:

Error CS1061 'ReadOnlyCollection' does not contain a definition for 'Click' and no accessible extension method 'Click' accepting a first argument of type 'ReadOnlyCollection' could be found (are you missing a using directive or an assembly reference?)

My code is:

var EQ = DesktopSession.FindElementByName(@"C:\Users");
var EQWindowHandle = EQ.GetAttribute("NativeWindowHandle");

EQWindowHandle = (int.Parse(EQWindowHandle)).ToString("x");    
EQWindowHandle = "0x" + EQWindowHandle;

DesiredCapabilities EQcapabilities = new DesiredCapabilities();
EQcapabilities.SetCapability("appTopLevelWindow", EQWindowHandle);

var EQSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), EQcapabilities);

EQSession.FindElementsById("7.8556.12446183").Click();

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

1

FindElementsById returns a ReadOnlyCollection.

You need to pick the relevant item from the collection before attempting to call click.

This will take the first item returned and then call click on it.

var elements = EQSession.FindElementsById("7.8556.12446183");

var element = elements.FirstOrDefault();

if (null != element)
    element.click();

Alternatively, if you're always sure that either, there is only one element with the Id 7.8556.12446183, or that you want to use the first element with that Id (there really shouldn't be more than one), then you could use FindElementById instead as below.

var element = EQSession.FindElementById("7.8556.12446183");

if (null != element)
    element.click();
Barry O'Kane
  • 1,189
  • 7
  • 12