Ask a Question

Getting the count of elements on the page

Frequent Contributor

Getting the count of elements on the page

Hi there,

I am trying to get the count of this object from the webpage and run the loop. The Count is returning null for me when I inspect in the console I have around 9. Also for this FindElements when I try to use the library functions its taking for ever to load and shows only spin.




Source code



2nd option

var TestedPage, CSSSelector

CSSSelector = "button[title='More options']"

TestedPage = NameMapping.Sys.browser.pageRavenCore.FindElements("//div[@data-testid='canvasItem']")

if I use TestedPage.QuerySelector(CSSSelector) I am getting the following error.




3rd option

for the following script I was able to get the object but still when I say object.Count its returning empty

 var res;

res= Aliases.canvas_card_Item.FindElements("button[title='More options']");
// Check the result
if (!strictEqual(res, null))
// If the element was found, output its HTML code
// If the element was not found, post a warning to the log
Log.Warning("The element was not found.");


4th option

var TestedPage

TestedPage = NameMapping.Sys.browser.pageRavenCore.FindElements("//div[@data-testid='canvasItem']")
Log.Message("canvasCard selector "+ TestedPage.Count) It printed undefined

Champion Level 3

Here's an example,


function Test1()
    var page = Sys.Browser().Page("");
    var artlist = page.FindElement("//section//div[contains(@class, 'artlist')]");
    var res = artlist.QuerySelectorAll("article");
    if (!strictEqual(res, null)) {
        Log.Message("Number of items found: " + res.length);
        for (var i = 0; i < res.length; i++) {
    } else {
        Log.Warning("The element was not found");


Frequent Contributor

Hi @rraghvani, I used the same document to get the code snippet and changed according to my requirement. But any how thanks for looking in to this. Actually I was able to fix the issue my self that the testedPage object I am using the wrong parent element. There is one more level up parent which refers to the complete frame, and after referring that element then I was able to get the correct count.

The fix is

CSSSelector = "div[data-testid='canvasItem']"

TestedPage = NameMapping.Sys.browser.pageRavenCore.canvas_Window

Using this the TestedPage.QuerySelectorAll(CSSSelector) returned the correct count

Showing results for 
Search instead for 
Did you mean: