Get the id of a table on a webpage

I would like to download the contents of a table using robocorp but the table id is dynamic, it changes when I load the page. There is only one table on the page, so I was thinking of getting the html as text, parsing it for the table id <table id=“xxx” , i.e. getting the xxx. Any ideas on how to do this. Or can I use class, summary or title as a locator and if so what does the locator look like when passing it to the Get Table Cell keyword?


You can indeed use various other selectors, and there’s no need to parse the HTML by yourself.

These are for instance options:

Get table cell    tag:table   ...
Get table cell    class:NameOfClass   ...

The various types are described in the keyword documentation:

If there are spaces in the class name then do you need to put quotes around it?

Quotes don’t seem to work! However I am getting an error:
Element ‘class:artdeco-global-alert__dismiss artdeco-button artdeco-button–circle artdeco-button–inverse artdeco-button–1 artdeco-button–tertiary ember-view’ not visible after 5 seconds.

If you know the order of the tables in page, you could use xpath with numerical index

    ${text}=  Get Table Cell  //table[1]  1  1

In many cases when locating elements, you don’t need to include all the CSS classes. In fact, adding too many classes to your selectors make them less resistant to changes, since they depend on all the classes being there.

Try to pick the least amount of identifying info. If you can share some of the HTML, you might get some suggestions for succinct selectors!

Thanks jani, this was helpful. What I noticed is that you don’t have to start at the beginning of the CSS classes string/list and I found a single class that worked two or three classes into the list.

1 Like