set text after tab

I’ve been having trouble finding the desired TestObject using xpath, but I was able to get around by clicking on an object above the desired input field and “tabbed” to the correct input field.

However, the only problem left is to input information using SetText, which takes an TestObject parameter.

Wondering if there is a way to get the current TestObject I have just tabbed to? Or if there is a way to set text to the input field without the need of TestObject?

Of course you can.
You need little jquery magic.
This will set value into active field:

WebUI.executeJavaScript(’$(document.activeElement).val(“YourValue”)’, [])

can you better describe structure of page?
can’t you use xpath like : (//xpath_to_known_obj//input)[n]
this will take n-th element from all you find with x-path expression in ()

Of course you can.
You need little jquery magic.
This will set value into active field:
WebUI.executeJavaScript(’$(document.activeElement).val(“YourValue”)’, [])

Tried and got the error

Unable to execute JavaScript. (Root cause: org.openqa.selenium.WebDriverException: unknown error: $ is not defined

I attempted the solution posed by here, and it works!

WebUI.executeJavaScript('document.activeElement.value = YourValue', [])

Follow up question. Is there a way to press “tab” from the current ActiveElement?

Answering my own question, I was able to accomplish through defining the following function:

	@Keyword	def KeyPress(Keys key) {		WebDriver driver = DriverFactory.getWebDriver()		Actions act = new Actions(driver);		act.sendKeys(key).perform();	}

and the following import statements:

import org.openqa.selenium.interactions.Actions as Actionsimport org.openqa.selenium.JavascriptExecutor as JavascriptExecutorimport org.openqa.selenium.WebDriver as WebDriverimport org.openqa.selenium.WebElement as WebElementimport org.openqa.selenium.Keys as Keysimport com.kms.katalon.core.annotation.Keywordimport com.kms.katalon.core.testobject.TestObjectimport com.kms.katalon.core.webui.common.WebUiCommonHelperimport com.kms.katalon.core.webui.driver.DriverFactory
2 Likes

Hi!

Thanks for your suggestion I have simiar issue and it works!

I have one question while using:

WebUI.executeJavaScript(‘document.activeElement.value = YourValue’, [])

How to plase YourValue as Variable defined earlier? When I type my variable name in this script it does not work.

Hi!
I have solved my problem it was trivial:

WebUI.executeJavaScript(“document.activeElement.value = ‘Amount1’”, [])

I just have to use my variable in ‘’.

Have another problem with this, even if I see that the active field is fillin with value from my variable, when it comes to saving the form entered value are not saving :frowning: fields are filled out with default value).