Forum Discussion
Just tried FindAll with Enabled=True. The same result.
Could you create a new project and select JavaScript as the language (or convert the code and use VBScript). Using Chrome, navigate to https://www.w3schools.com/css/css3_buttons.asp and run the following code,
function GetAllButtons()
{
var browser = Sys.Browser("chrome");
var page = browser.Page("https://www.w3schools.com/css/css3_buttons.asp").Panel(2).Panel(0).Panel("belowtopnav").Panel(0).Panel("main");
var buttons = page.FindAll("ObjectType", "Button", 1);
Log.Message(`Number of buttons on page ${buttons.length}`);
}
Does it work, and does it return 56 buttons? I just want to eliminate and ensure that FindAll method is working as expected, before proceeding to the next step.
- pkudrys13 days agoFrequent Contributor
So, what happens is, that your code works, as expected. However, it fails in case there is used an Alias element as a parameter.
It seems to me as a TC problem? Or is there another way how to get an array of items from an alias element, whose xpath points to multiple elements?
- rraghvani13 days ago
Champion Level 3
Using the code example that I had provided i.e. GetAllButtons(), the following line of code
browser.Page("https://www.w3schools.com/css/css3_buttons.asp").Panel(2).Panel(0).Panel("belowtopnav").Panel(0).Panel("main");
matches with,
Name mappingName mapping and aliases. Note, the that hierarchy structure is kept the same as shown in the Object Browser.I can use the mapped object like so,
function GetAllButtonsAliases() { var buttons = NameMapping.Sys.browser.pageCssButtons.panelCss.panelCss.panelBelowtopnav.panelCss.panelMain.FindAll("ObjectType", "Button", 1); Log.Message(`Number of buttons on page ${buttons.length}`); }
Or via the the aliases name,
function GetAllButtonsAliases() { var buttons = Aliases.browser.pageCssButtons.panelMain.FindAll("ObjectType", "Button", 1); Log.Message(`Number of buttons on page ${buttons.length}`); }
They all produce the same results,
The difference, is that I'm looking for the criteria where ObjectType equals Button, in panelMain. Whereas, you are looking in button and this will return 1 object. You need to ensure you are finding the appropriate "children" within the "parent" node.
Using XPath in name mappingUsing function- pkudrys13 days agoFrequent Contributor
OK, I see. Thank you for your help! Unfortunately, this is not what I'm looking for. It's similar to FindElements solution from my initial post :) Also in this case, I need to use "parent" element, to find "child" elements.
What I want to do, is to directly use a mapped element, pointing to multiple elements. I'm quite surprised there is no simple way to obtain the list of elements from a mapped element, whose xpath is pointing to multiple elements. Basically, I don't want to use parent/child relationship and define additional property names/values in code, to find certain child elements.
Just for fun here is the xpath I'm using:
//div[contains(@class, 'editFormHeader')]//*[contains(local-name(),'mat-checkbox') or contains(local-name(),'mat-form') or contains(local-name(),'mat-select') or contains(local-name(),'mat-button-toggle') or contains(local-name(),'mat-radio-button')]//*[(name()='input' and not (contains(@class,'fake'))) or name()='textarea' or name()='mat-select' or (name()='button' and not (@aria-label='Clear') and not (@id='globe') and not (@type='submit'))]
As you can see, it's quite complicated xpath, but it works nicely. It returns only expected form elements. I'm using this approach also in Ranorex, where I can quickly get the list of elements from a mapped object, using simple iList and CreateAdapters method. No need or defining and referring parent element. As it seems, there is no similarly simple way to achieve this in TC?