Saving complex variable returns from Javascript

Hello, I’m trying to run some javascript and store that value in a variable. The value that returns is an HTML collection, not a string. It doesn’t seem to be working, the variable doesn’t exist in the variables tab and I’m not able to use it anywhere.

What I’m trying to do is grab a list of links so I can iterate and click through each one to check the data on each page. The links are in columns in a table.

You can convert any HTML element into a string representation by querying its outerHTML property

See also:

1 Like

I don’t need a string though, I need all the rows in a table that I can iterate over.

Out of interest, do you know how many rows there will be? e.g. is it a fixed length?

No. I need to be able to grab any amount of rows

It’s a real shame that KR does not have a published set of APIs we can interrogate – I have no clue about the output from runScript (@vu.tran)

Hopefully, this ancient reply from one of the original developers will help you:

Remember, search is your friend. :sunglasses:

It may be convoluted, and there might be better ways, but I was thinking you could potentially use JavaScript (via runScript) to grab the full HTML tag for the table, do a count on the number of <tr> tags (to get the number of rows) within the table via the string for that element, then use that value to iterate through each row in a loop.

That’s a non-starter, IMO.

I tend to agree with this, but from a different perspective.

KR (read as Katalon Recorder and that is all) should be regarded as a helper.
The origin of it is in Selenium IDE.
Read that carefully…
Those tools were never designed to be a full stack of tools to magically design and implement AQA solutions.

Altough this tool have the capability to also run the recorded tests, and have also a CLI companion, is not complete and should be never used for such full scope.

What is great in this/those tool(s) is, you can quickly design some draft for automated scripts.

Even more, you can quickly export them as pyton, java, whatever else language supported.

But this is where the magic ends.

Personally i will use this tool only in the above mentioned scopes and further refine the produced script to create my own framework.

To complain for lack of features for a browser addon (which KR is, in the end) makes no sense for me.

Abusing this addon for complex solutions, you abuse the underhood browser.


1 Like

A tool like many things in life is what we make of it. If you believe something should be limited to X, then X is all it will ever do for you. If you have a broader view on it, and approach things laterally, then sometimes the potential can be so much more.

I get that certain tools are more ‘natural’ fits for certain applications than other tools, but ultimately, it’s down to the individual to choose what suits them (even if it’s something that you yourself would never use in such a way).

Russ wasn’t (nor anyone else here was) really complaining about the limitations in place, more lamenting the possibilities that (using his example) supporting APIs may bring to the table.

I don’t see what there is to gain by being critical of those who like something and choose to use it, after all, it’s their choice, and they aren’t forcing anyone else to switch tools just because they are using it either.

@guy.mason yeah, i saw you are typing something.

the code of KR and Selenium IDE is free and opensourced.

if you feel it can be improved, you are welcome to contribute

Not sure about what API you complain.
look at the code, improve it at will

I didn’t complain about APIs :slight_smile: Was only mentioning that Russ had mentioned the potential advantages of having a published set of APIs, from an integration PoV.

@samantha.mott I’ve not ‘tested’ this on the site that you’re using, but the following script could potentially be used (obviously fill in your own assertions, verifications, etc related steps on the pages that you’re opening).

It starts at the second row (so it’s assuming the first row is just the headings for the table). It also assumes that the link is in the first column of the table.

PS. If you end up with failures due to what is effectively race conditions, then you’d also want to add waitFor(XX) type commands in there too.

Ah … well, I don’t think there is such, but the entire code is available at:

It’s just JS …

Well … I don’t think it should be limited, I tried to point that, how it is designed, the user cannot expect magic.
A browser app / addon have some limitations … from the browser himsel first of all.
So, being pragmatic, and considering this tool is not monetized, I do not expect complex features to be implemented very quick.
But anyway, the code is open, so user contributions is welcomed.
This is why, in my opinion, I will never treat this tool as a full solution, but only as a helper.

1 Like