2gis / Winium.Mobile

Winium.Mobile is Selenium Remote WebDriver implementation for automated testing of Windows StoreApps and Silverlight apps, tested on emulators (currently only Windows Phone/Mobile apps are supported).
Mozilla Public License 2.0
51 stars 29 forks source link

Getting only the first element #148

Closed naix86 closed 8 years ago

naix86 commented 8 years ago

Can I get a collection of element with the same automationId?

NickAb commented 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')
naix86 commented 8 years ago

Hi,

Is find_elements_by_id understand RemoteWebDriver?

Cause I have only FindElementsById

NickAb commented 8 years ago

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.

naix86 commented 8 years ago

I see, I am on C#; doing xamarin.forms (Cross-platform)

When I use FindElementsById, it is returning me things that are not very helpful

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" } ] }

15:11:33 [DEBUG] Client closed

But when i use FindElementById, it is returning me the first element text ONLY

NickAb commented 8 years ago

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);
NickAb commented 8 years ago

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.

naix86 commented 8 years ago

Cool, thank you.