How to send a string at the current focus

Send_keys(*keys_to_send) - an element that sends a key to the current focus
Send_keys_to_element(element, *keys_to_send) - send a key to the specified element

I use Kataion Studio 6.1.2.
I want to know how to send a string at the current focus, because login box has no elements, So I want to send a string at the current focus, selenium it can do this.

Just use null instead of TestObject value.

WebUI.sendKeys(null, 'abcd')

1 Like

Hi Marek_Melocik,

I still send unsuccessful. I have switched the input to English(US). Is there any other reason? I have upgraded to 6.1.3.

logs:
Test Cases/nas login FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to send keys ‘admin’ to object
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:834)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$1.call(Unknown Source)
at nas login.run(nas login:23)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1557123533916.run(TempTestCase1557123533916.groovy:21)
Caused by: org.openqa.selenium.UnhandledAlertException: Dismissed user prompt dialog: https://10.40.0.112 requeste your username and password. The website says:“ReadyNAS Admin”:
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘NJ–T470’, ip: ‘10.40.1.66’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: com.kms.katalon.core.webui.driver.firefox.CGeckoDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 66.0.4, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 16816, moz:profile: C:\Users\bzhao\AppData\Loca…, moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, proxy: Proxy(direct), rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 035f3a2a-f744-451c-8099-90b7a2334bb0
*** Element info: {Using=css selector, value=body}
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at com.kms.katalon.selenium.driver.CFirefoxDriver.execute(CFirefoxDriver.java:28)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:397)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByCssSelector(RemoteWebDriver.java:468)
at org.openqa.selenium.By$ByCssSelector.findElements(By.java:441)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:358)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElements(WebUiCommonHelper.java:761)
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1093)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:27)
at com.kms.katalon.core.webui.keyword.internal.WebUIAbstractKeyword.findWebElement(WebUIAbstractKeyword.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.doCall(SendKeysKeyword.groovy:52)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword$_sendKeys_closure1.call(SendKeysKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.sendKeys(SendKeysKeyword.groovy:60)
at com.kms.katalon.core.webui.keyword.builtin.SendKeysKeyword.execute(SendKeysKeyword.groovy:38)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys(WebUiBuiltInKeywords.groovy:834)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$sendKeys$1.call(Unknown Source)
at Script1557051447606.run(Script1557051447606.groovy:23)
… 11 more

Script:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(‘’)

WebUI.navigateToUrl(‘https://10.40.0.112/admin’)

WebUI.delay(5)

WebUI.sendKeys(null, ‘admin’)

WebUI.sendKeys(null, Keys.chord(Keys.TAB))

WebUI.sendKeys(null, ‘password’)

WebUI.click(findTestObject(‘Object Repository/Page_nas-E7-27-10/div_Apps’))

WebUI.click(findTestObject(‘Object Repository/Page_nas-E7-27-10/div_Installed Apps_x-frontview-tabitem-tabbtnicon’))

image

Hi,

Is there any specific reason you want to send string to current focus? You mentioned that login box has no elements. I think username and password should be some sort of input. If yes - you can locate through xpath

(//input)[1]

is it possible to share screenshot with HTML structure so I can help you better.

  • Priyank

My input username and password is a popup.

I use selenium it can send the username, “admin”, I am not sure why this can’t be sent.

user prompt dialog.

Looks like, It is authentication pop up. You can refer below information over the forum if it helps. I have doubt , it can directly send string to the text.

You may need to use AutoIT or Robot class to deal with it.
https://docs.katalon.com/katalon-studio/docs/using-autoit-for-authentication-in-katalon-studio.html

Just for the curiosity purpose- Did you check below stuff (Few yeas back, it has worked for me)

You can provide credentials in URL itself it means we will add username and password in URL so while running script it will bypass the same.

Syntax

http://username:password@url

Example :

http://priyank:password@www.xyz.com

**Other guess: **

  1. Try:
'Open browser and navigate to demo AUT site.'
WebUI.openBrowser('')

'Input username and password on authentication dialog.'
WebUI.authenticate('http://url', 'username', 'password', 12)

  1. what about if we create firefox / chrome profile where you can provide this authentication and ask katalon to load profile at runtime? - It has also worked with selenium in past. However, not tried with katalon.

Hi priyank.it

Thank you for your help. I have successfully login with AutolT.

I am writing a username and password in the URL. I still can’t login.

‘Open browser and navigate to demo AUT site.’
WebUI.openBrowser(’’)

‘Input username and password on authentication dialog.’
WebUI.authenticate(‘http://url’, ‘username’, ‘password’, 12)

I also tried this way, I used chrome(74.0.3729.131) and firfox(66.0.4) , also I can’t login.

Anyway, I can use it now. Thanks!