How to search and count values in table that is within iframe?

Hello to all,

I have some values in a table that is in a iframe that I want to store in a variable.

The xpath of the values is like this:


When I tried the complete xpath I get “0” as result. If I tried adding “.*” after “888393” then the result is more than 6000.

    Command      |             Target                        | Value | Result
    SourceSearch | regex=//*[@id="888393_1234_993_11"]/td[2] | var   |
    echo         | ${var}                                    |       | 0
    SourceSearch | regex=//*[@id="888393_.*td[2]             | var   |
    echo         | ${var}                                    |       | 6202

How would be the correct regex to match all the values in table and store in ${var} the number of these elements?

Thanks for any help.


Is many solution

You have selectFrame command

I prefer
command executeScript

where in value commad place

return document.getElementById('888393_1234_993_11').contentWindow.document.querySelector('yours table')

Hi Emil,

Thanks for your answer. But I don’t know the values in table, so first I need I way to know previously which values are in column 2.

If value 1234 is in table, then the xpath contains 1234 within it. Because of that I was trying with Regex in order to check if I was able to catch all values and store them in a variable to use them later.

I hope make sense.


Ok you must looping on table rows


return [...document.getElementById('iframe_id').contentWindow.document.querySelector('your_tbody').querySelectorAll(tr)].map(x => x.querySelector('td')[nb_of_col].innerText)```

expected Array

Hi Emil,

Thanks for the help. I’m new to Javascript and I wasn’t able to fix the issue trying your example.

If I try this part of your command in Console of Developer tools in Chrome.


I get this error

VM12695:1 Uncaught ReferenceError: tr is not defined
    at <anonymous>:1:104

Now if I try only this part of the command


I get this html block:

	<tr><td><table class="class1"..>
	<tbody><tr><th class="left">&nbsp;</th>
	   <table width="100%"..>
		<table border="0" ...>
<form name="MyForm">
	<table class="MyTable" ..>
				<th width="15">&nbsp;</th>
			<tr class="tbl-x" id="1234_992_120_24" onmouseup="..">
				<td width="10">
					<input type="checkbox" name="Item12340" onclick="javascript:.._item('77373','992','abc')">
				<td align="right">
					<a href="javascript:...('77373','992','abc');.._Open('1234','NS');">992</a>

So, the values I’m looking for are in 2nd column of the table “MyTable” that is inside the form “MyForm”. In this sample showing only 2 “tr’s” and only 2 “td’s” in second “tr” the value I’d like would be 992. This value appears in tr’s id, within the “onclick” and within the < “a href=”…992…">992</a" >

How woudl be the way to the get all the values for column 2 of table MyTable?

Thanks for the help so far.



return  document.getElementById('iframe_id').contentWindow.document.querySelector('copied js path <- anchor have 992').innerText

I copied the JS Path and this command gets the value I want. The JS Path is like this:

#\\45 00340_992_120_24 > td:nth-child(2) > a

And command that works is:

document.getElementById('iframe_id').contentWindow.document.querySelector("#\\45 00340_992_120_24 > td:nth-child(2)  > a").innerText;

But in this case I need to know previously the JS path and I’d like to store in an array or variable all values in column 2 of that table automatically without to know previously the values or JS paths for each one. Maybe something like mixing your first solution with the code that works or is possible to add a regex? I don’t know.


return […document.getElementById('iframe_id').contentWindow.document.querySelector('.MyTable > tbody').querySelectorAll(tr)].slice(1).map(x => x.querySelector('td:nth-child(2)  > a').innerText)


return […document.getElementById('iframe_id').contentWindow.document.querySelector('.MyTable > tbody').querySelectorAll(tr)].map(x => x.querySelector('td:nth-child(2)  > a').innerText)

I can’t see this table this is problem.

I’m not sure why is not working, trying your commands I get

VM36857:1 Uncaught TypeError: Cannot read property 'contentWindow' of null
    at <anonymous>:1:41

This is how it looks the real file if could help.

Thanks again


Do you have selected top iframe ?

Yes, top iframe is selected. Why?