Hi guys !!
Is there a way to use sent keys without having an object? I want to simulate a keyboard entry after selecting a tab but it does nothing due it not having an object to select but does pass “Keys 'ESCAPE + ’ sent to object: ‘tempBody’”
Hi guys !!
Is there a way to use sent keys without having an object? I want to simulate a keyboard entry after selecting a tab but it does nothing due it not having an object to select but does pass “Keys 'ESCAPE + ’ sent to object: ‘tempBody’”
You could try to target the HTML <body>
element. Not sure if it will work, though…
java.awt.Robot
class should be agnostic of any selected element, acc. to the description.
https://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
It is designed to send ‘native inputs’
I never use it, you can give a try.
You have to grab the jar and import it in your project, i think it is not provided with Katalon by default
Robot works great for this. I use it quite oftem when I am unable to capture objects with Katalon.
import java.awt.Robot
import java.awt.event.KeyEvent
Robot robot = new Robot();
robot.keyRelease(KeyEvent.VK_ENTER)
and so on. What I have not been able to figure out is how to send a String value using Robot since Katalon wants to make me target an object.
What are you sending a string to if you don’t have an object, if you don’t mind me asking? You could continue to send a key one at a time if you wanted - it goes in the sequence of ‘keyPress’ then ‘keyRelease’ for each character… or you could make a loop to reduce the amount of lines (two per character)! I haven’t really needed to submit characters beyond a single one
I am just now trying to send a string value using Robot and not having much luck. This is a field in outlook webmail in the advanced filter section and none of the elements are letting me capture them. I have seen a few examples out there, but it is not working. I am trying this now.
import java.awt.Robot
import java.awt.event.*
import java.lang.Character
import org.openqa.selenium.Keys as Keys
String searchString = 'lieninfo'
Robot robot2 = new Robot();
//Looping through every char
for (int i = 0; i < searchString.length(); i++)
{
//Getting current char
char c = searchString.charAt(i);
println('char c: ' + c)
//Actually pressing the key
robot2.keyPress(char.(c));
robot2.keyRelease(char.(c));
Thread.sleep(250);
}
I get:
Reason:
groovy.lang.MissingPropertyException: No such property: c for class: char
Try the above with no period – char(c). Groovy is translating the quoted phrase to an object and its method, like “searchString.charAt(i)”.
I was able to get it working using:
for (int value : searchString.substring(0).toCharArray()) {
int keyCode = KeyEvent.getExtendedKeyCodeForChar(value)
robot.keyPress(keyCode)
sleep(100)
robot.keyRelease(keyCode)
}
Yes you can send it
hi noor,
sometime I am intrigued by your posts.
sometime you ‘provide’ solutions, sometime you are asking for dumb solutions, sometime you are rising ‘interesting’ topics.
are you a Kudos hunter or what?