This is hopefully a straightforward solution for someone out there with far more experience than I. My application has rows inside a parent element. Each row is segmented so it also appears to have columns. I need to get all the “add user” buttons that are in a ‘column’ together in one array and loop through it.
Roughly
<div> <row 1> <stuff I dont need> <button I do need> <row 2> <stuff I dont need> <button I do need> <row 3> <stuff I dont need> <button I do need></div>
I believe the FindAll or FindAllChildren is the correct route but I am getting empty arrays returned. The buttons all have the same text “Add User” and are SPAN elements (not actually a button element). The buttons are all in the rows as I described and are contained in one parent DIV that wraps around all the rows. (Unfortunately not the column).
This is close to what I have without sharing exact code:
let column = page.FindElement("//div[contains(@class, 'random-css')]"); Log.Message(column.FindAllChildren("SPAN", "Add User", 300000))>> returns nullThank you
First off, thank you! I had not found that method before and it seems very useful. Second I tried implementing it into my code and while I did not get an error I also did not seem to get success. What I did get was an empty response row in my TC log, and when I created a loop around my column element I then got 14 empty responses in TC, when there are 21 rows. Could the issue be that I am logging my result in a message?
Updated from your suggestion:
let column = page.FindElements("//span[.='Add User']");
for(var i = 0; i < column.length; i++) {
Log.Message(column[i])
}
Scot1967 I rescind my earlier response, I think with enough tweaking and inspecting I can work with the solution you provided. Thank you so much! Solved
If you are not returning an empty array then you should see objects if you inspect the array by setting a break and a watch. The array will contain objects so you will need to refer to an object property to log anything.
Maybe like this? (Not sure what properties you have)
let column = page.FindElements("//span[.='Add User']");
for (var i = 0; i < column.length; i++) {
Log.Message(column[i].Name);
}