Get element in page and copy to string

Hi, i need get a content of element in page and send value to one string, to after create a path with the name of this content element.

Exampe:

In the page i have this HTML code: <h3 class="c-heading">Computadores Windows</h3>

I need make the code search to <h3 class="c-heading">**" and "**</h3>
And copy all inside (in this case, is “Computadores Windows

After need send the content “Computadores Windows” to a string, to after make a path with this name.

How i can make the Katalon get this element?
And the content is changed in any reload page, because this i need tell the script to search to <h3 class="c-heading"> and </h3> and copy all inside.
If i use class or ID, don’t will work any times, because the page have the same CSS class and id in anothers div

I try this, but don’t work.

I see the problem is because have 2 same elements in the page.

In PHP or iMacro, i can tell the script to find the fouth element <td> in the page, copy all after this and stop whe find the next </td>

I can do any like this in Katalon?

Because i need get text’s of table, and all to separate the text is TD tags.

And do BOTH elements look like this?

If they do, I need to see a lot more of the HTML.

I will send the example of my code in iMacro to you see what i do. And after, the page HTML code and what i need copy.

In iMacro for example, i tell the script to get the value of Thrirth TD:
TAG POS=3 TYPE=TD ATTR=TXT:* EXTRACT=TXT

The code of page is this:

<div class="panel-body">
	<table class="table table-bordered">
	<tbody><tr>
		<td colspan="4" class="titulo">Informações Pessoais</td>
		</tr>
    		<tr>
    			<td class="sub_titulo">Name</td>
    			<td>AAAAAAAAA</td>
    			<td class="sub_titulo">COD</td>
    			<td>123456789</td>
    		</tr>
    		<tr>
    			<td class="sub_titulo">Mother</td>
    			<td>BBBBBBBBB</td>
    			<td class="sub_titulo">School</td>
    			<td>CCCCCCCC</td>
    		</tr>
    		<tr>
    			<td class="sub_titulo">Date</td>
    			<td>2019</td>
    			<td class="sub_titulo">E-mail</td>
    			<td>-xxxxxxx@xxxxxx.com</td>
    		</tr>
	</tbody></table>
 </div>

I need copy the name “AAAAAAAAA” and COD “123456789” and use this for a string, to next i create a path of the name “AAAAAAAAA” and save page with name “123456789.pdf”

The all code to save page i have, but i don’t know how tell the script to get the name AAAAAAAAA and transform in string, to after i call the string in place of name the path.

hi,

try to use WebElement class
WebElement simpleTable = driver.findElement(By.className(“table table-bordered”));

List rows = simpleTable.findElements(By.tagName(“tr”));
assertEquals(4, rows.size());

// Print data from each row
for (WebElement row : rows) {
List cols = row.findElements(By.tagName(“td”));
for (WebElement col : cols) {
System.out.print(col.getText() + “\t”);
}
System.out.println();
}

I need add any “import” to page?
Because i try here and get an erro:

unable to resolve class WebElement
@ line 20, column 12.
WebElement simpleTable = driver.findElement(By.className(‘table table-bordered’));

EDIT:

I add all this imports:

import internal.GlobalVariable

import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import org.openqa.selenium.interactions.Actions as Actions
import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

And i get a error now: Unable to locate element: .table\ table-bordered

Create a test object with an xpath like this (if there are multiple tables on the page, you will need to add a predicate to the //table portion to make sure you are locating the right table):

Get the string value for that element like this:

String string = WebUI.getText(findTestObject("path/to/my/test/object", ["rowIndex" : "1", "columnIndex" : "2"]));

(Make sure you provide the rowIndex and columnIndex arguments when you call findTestObject(), as I’ve shown).

1 Like

@Brandon_Hein

Thanks for you reply.
i tryred here and works good!

But now i get a new problen.

Is some pages, the numbers of rows is 5, and in another cases is more.
Have some code i can use to tell the script to copy all rows of table to me?

And in another page, have 3 tables.
How i do to determin the table 1, table 2 and table 3 in the code?
To i can tell the to te code what i need copy from the table 1, and of anothers tables.