How to Get this ID How to Get this ID selenium selenium

How to Get this ID


Unfortunately you won't be able to access this field because the method "FindElements" returns the elements in the form of IWebElement. IWebElement does not have a method implemented to get the ID value you are looking for.

If the FindElements method was to return the type RemoteWebElement, or even ChromeWebElement, we would be able to access this field because the RemoteWebElement has a method to access it. However, this method is not implemented in the interface. So there is no way for us to get it. I've played around with casting and haven't been able to cast in the correct spot. So as of now, I'm not seeing a way to get this ID.

See RemoteWebElement.cs source code for more information:https://github.com/SeleniumHQ/selenium/blob/master/dotnet/src/webdriver/Remote/RemoteWebElement.cs

Hopefully this helps you out a bit


If you want to get the IDs from all elements as a List<String> you could do

List<String> query = qntd.Select(it => it.Id).ToList();


It's a special id generated by the driver itself, not html property. You can use type cast to RemoteWebElement and then get this value using reflection as it is protected. But hardly this is the thing you need in your tests.

https://seleniumhq.github.io/selenium/docs/api/dotnet/?topic=html/P_OpenQA_Selenium_Remote_RemoteWebElement_Id.htm