Closed naix86 closed 8 years ago
Yes, you can do so by using FindElements
command. In python, for example, it will look something like that:
elements = driver.find_elements_by_id('MyAutomationId')
Hi,
Is find_elements_by_id understand RemoteWebDriver?
Cause I have only FindElementsById
What language are you writing your tests in? The method name is dependent on language.
In python it is find_elements_by_id
, in C# it is FindElementsById
, in Java it is findElementsById
.
I see, I am on C#; doing xamarin.forms (Cross-platform)
15:11:33 [INFO] COMMAND findElements { "using": "id", "value": "listId", "SESSIONID": "c6d5baba-ffd2-4396-9d56-ab714134ff92" } 15:11:33 [DEBUG] Sending request to inner driver: http://169.254.80.80:59477/ 15:11:33 [DEBUG] RESPONSE: OK: { "sessionId": "c6d5baba-ffd2-4396-9d56-ab714134ff92", "status": 0, "value": [ { "ELEMENT": "17516314-1" }, { "ELEMENT": "29341896-2" }, { "ELEMENT": "29050190-3" }, { "ELEMENT": "24091184-4" } ] }
But when i use FindElementById, it is returning me the first element text ONLY
FindElementsById
will return collection of elements having AutomationId equal to one specified.
If you want to get text of those elements, then you will need to iterate over the collection returned by driver and request text value of each element. For example:
var values = driver.FindelementsById("SomeId").Select(x => x.Text);
Are you using Visual Studio 2015 or ReSharper? It should suggest references and using statements so that you can use LINQ queries (see https://msdn.microsoft.com/en-us/library/bb397900.aspx for listing of references and using statements).
Anyway, you can use plain old foreach:
var values = new List<string>();
foreach (var item in driver.FindelementsById("SomeId"))
{
values.Add(item.Text);
}
but it will require collections using statement, etc. Anyway, it is a question more about language or selenium in general, then about Winium.
Cool, thank you.
Can I get a collection of element with the same automationId?