# Get customKeywords variables

**URL:** <https://forum.katalon.com/t/get-customkeywords-variables/12861>\
**Category:** Miscellaneous\
**Created:** [August 27, 2018, 5:29pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861 "2018-08-27T17:29:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mateus\_Gomes\_Binatti](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Mateus\_Gomes\_Binatti](https://forum.katalon.com/u/Mateus_Gomes_Binatti)\
**Post date:** [August 27, 2018, 5:29pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/1 "2018-08-27T17:29:02Z")

</div>

Hello, guys!

I’ve created a customKeyword method for enter in a website and get a “cpf”:

```auto
public class buscaNovoCpf {
	@Keyword
	def coletarCpf(){		
		WebUI.openBrowser('');
		WebUI.maximizeWindow();
		WebUI.navigateToUrl('https://www.geradordecpf.org/');		
		WebUI.delay(2);		
		def driver = DriverFactory.getWebDriver();		
		WebElement btnGerarCpf = driver.findElement(By.cssSelector('#btn-gerar-cpf'));
		btnGerarCpf.click();	
		def cpfValue = WebUI.executeJavaScript('return $(".col-sm-8 #numero").val()', []);
		println(cpfValue);			
	}
}

```

CPF is a personal document here in Brazil and this website provides a fake for testing purposes.

If i want to use the variable “cpfValue” in a test case, how can i access this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 27, 2018, 5:38pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/2 "2018-08-27T17:38:52Z")

</div>

If I’ve understood correctly…

```auto
	String coletarCpf(){		
		WebUI.openBrowser('');
		WebUI.maximizeWindow();
		WebUI.navigateToUrl('https://www.geradordecpf.org/');		
		WebUI.delay(2);		
		def driver = DriverFactory.getWebDriver();		
		WebElement btnGerarCpf = driver.findElement(By.cssSelector('#btn-gerar-cpf'));
		btnGerarCpf.click();	
		def cpfValue = WebUI.executeJavaScript('return $(".col-sm-8 #numero").val()', []);
		return cpfValue
	}

```

In your test case…

```auto
println(/* The call to your coletarCpf Keyword*/)

```

---

<div class="post-metadata">

**Author:** ![Mateus\_Gomes\_Binatti](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Mateus\_Gomes\_Binatti](https://forum.katalon.com/u/Mateus_Gomes_Binatti)\
**Post date:** [August 27, 2018, 5:43pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/3 "2018-08-27T17:43:33Z")

</div>

Hello, Russ

My idea is something like this:

```auto
CustomKeywords.'metodosGenericos.buscaNovoCpf.coletarCpf'();
WebUI.setText(findTestObject('Page_ (4)/input_defaultDocumentValue'), 'cpfValue');

```

Call the method that will return the cpfValue and “paste” him at the right field on the form.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 27, 2018, 5:46pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/4 "2018-08-27T17:46:41Z")

</div>

Try this, Mateus :

```auto
String cpf = CustomKeywords.'metodosGenericos.buscaNovoCpf.coletarCpf'()
WebUI.setText(findTestObject('Page_ (4)/input_defaultDocumentValue'), cpf)

```

But make sure you change coletarCpf to type String (see my last post).

---

<div class="post-metadata">

**Author:** ![Mateus\_Gomes\_Binatti](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Mateus\_Gomes\_Binatti](https://forum.katalon.com/u/Mateus_Gomes_Binatti)\
**Post date:** [August 27, 2018, 5:56pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/5 "2018-08-27T17:56:20Z")

</div>

Thank you so much, Russ, it worked fine for me!!

Best regards, bro!

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 27, 2018, 6:52pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/6 "2018-08-27T18:52:26Z")

</div>

You’re welcome. And thanks for the BA B)

---

<div class="post-metadata">

**Author:** ![henrryy.edward](https://avatars.discourse-cdn.com/v4/letter/h/c77e96/32.png) [@henrryy.edward](https://forum.katalon.com/u/henrryy.edward)\
**Post date:** [June 11, 2026, 7:30am UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/7 "2026-06-11T07:30:44Z")

</div>

Returning the value from the keyword is definitely the cleanest solution. It keeps the keyword reusable and avoids relying on global variables.

For test automation, I also prefer generating fresh test data on demand rather than storing static values. For example, when I need to [gerar cpf](https://gerador-br.com/) for validation or form testing, returning the generated value directly from the keyword makes the test much easier to maintain.

---

<div class="post-metadata">

**Author:** ![arvind.choudhary](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arvind.choudhary/32/33165_2.png) [@arvind.choudhary](https://forum.katalon.com/u/arvind.choudhary)\
**Post date:** [June 11, 2026, 2:46pm UTC](https://forum.katalon.com/t/get-customkeywords-variables/12861/8 "2026-06-11T14:46:58Z")

</div>

Yes, Keywords or any reusable test artifacts are anytime the best choice in the script
