Forum Discussion
It's an Angular-based app. I just found a public sample page, where this can be tested:
https://material.angular.dev/components/chips/overview#autocomplete
I've updated the test project with this particular page and elements.
Basically, I need to find all mat-chip-rows and click [x] button for each row. Of course, I know there is an easy way to achieve this by using name mapping and simple loop. But I can't use it that way. This project is just a simplified sample. In original project, I'm collecting all form inputs (using the complicated xpath) and do various things for each input. Basically collecting IDs/values, storing them in JSON, eventually loading IDs/values from JSON and filling individual form inputs. Therefore, I'm working on a generic method, which should work with various forms, containing variable number and types of elements.
Hello!
I'm also working on an Angular project. For this type of project, I exclusively use XPath to retrieve my objects.
In your example, here's what I would do:
let ar = page.FindElements("//div[@role='presentation']//mat-chip-row"); //page is your parent object, this xpath returns an array of all the mat-chip-row inside your div.
- rraghvani2 months ago
Champion Level 3
There's a subtle difference between FindElement and FindElements, an easy mistake to miss!
pkudrys just want to reiterate, FindAll method will only work on those objects that appear in the Object Browser.
Standard methodsExtended methodsOtherwise, you will have to implement your own "FindAll" method. Which means finding the parent node first, and then iterating through each child node, any node that matches your criteria, you then save and append that node to an array - this is real programming, and you'll have total control of your search criteria!
- eykxas2 months agoRegular Contributor
I don't understand the issue here. He wants to get the list of all mat-chip-row and then doing something (click on the [X] button).
With FindElements (and the proper xpath) he gets an already populated array, and just need to iterate through.
That's what I'm doing in my projet, and it works fine. Without needing NameMapping.