Forum Discussion
Here's the issue - the same code, just commented out line 3
function GetAllButtonsFromAlias(aliasItem)
{
//var parentElement = aliasItem.parentElement;
var buttons = aliasItem.FindAll("ObjectType", "Button", 100);
buttonsArray = buttons.toArray();
Log.Message(`Number of buttons on page, using NameMapping ${buttonsArray.length}`);
}
function test1()
{
//GetAllButtonsFromAlias(Aliases.browser.pageCssButtons.buttons.Parent);
Log.Message(Aliases.browser.pageCssButtons.buttons.parentElement.nodeName);
}
When calling parentElement (line 12) it is retrieving the buttons' parent element, which is <p> (highlighted in yellow)
Aliases.browser.pageCssButtons.buttons highlights "Default Button" for meThe element <p> does not appear in the Object Browser
As mentioned in the documentation,
Use FindAll to search for all objects that have the specified values of the specified properties. The search is performed in the object hierarchy displayed in the Object Browser panel starting from the testedObj object and continuing down the hierarchy to the specified depth.
Hence, FindAll does not work on <p> element.
If I uncomment line 11 and comment line 12, and use Parent (highlighted in yellow) instead of parentElement, then 61 buttons are returned (highlighted in green)
To make your function return the appropriate number of items, don't use line 3, but do pass parameters like "Aliases.browser.pageCssButtons.buttons" or "Aliases.browser.pageCssButtons.buttons.Parent".
Hopefully, this should also resolve your issue with your other post relating to "FindAll returns only one (first) element"
Thank you for your investigation! I really missed the part about Object Browser requirement. Unfortunately, the solution you are suggesting is not what I can use. The above sample is just a simplified example, not the real-world problem.
If you check my original code in the first post, I need to get the list of mat-chip-row tags, which are located on the same level as the inputElement (alias item). And because watch list shows directly what I want under the node parentElement property (of the obtained alias element), I hoped to use it in my code.
Is there another way to get the list of items according of my needs? Using alias element, pointing to the input, instead of direct parent element, is apparently not an option?
In other words, is there a way to get a direct HTML parent (not mapped parent) of an element, which is referenced by the Alias object?
- rraghvani2 months ago
Champion Level 3
I had to do some research, since you are trying to access non native objects, i.e. objects that don't appear in the Object Browser.
I've written a small program, then spent ages trying to figure out why parentElement.children was only returning one object, which just had a property value of length!
As it's a collection of child elements, I need to call the method item i.e. parentElement.children.item(i) which then returns each of the child elements. This prints out the following
Which matches the HTML code
Are you able to do something similar, so that it retrieves mat-chip-row's? You might have to use a different property other than tagName
- pkudrys2 months agoFrequent Contributor
Thanks for the investigation! Yes, this approach kind of works. I can retrieve the mat-chip-rows this way. The problem is, I can't do anything with them :) They can't be clicked or used as a reference for any of the Find functions (to find certain element in them). Getting the same "xxx is not a function" error.
In a meantime, I tried slightly different approach using FindElementByXPath using aliasItem as a reference. But to my great surprise, even this approach does not work. It simply does not find the aliasItem's ancestor element, even though the same xpath works fine in chrome dev. mode.
var findParent = aliasItem.FindElementByXPath("./ancestor::div[contains(@class,'w3-row')]")
- rraghvani2 months ago
Champion Level 3
JavaScript in TestComplete is powered by V8 engine v5.8, and Chrome DevTools will be something like V8 v13.7.152.17.
Since you are working with non standard elements, you may have to implement your own "Find", "Click" etc methods. But before doing that, read through Using Custom Attributes of Web Objects? Refer to this Support for Web Controls