XCommand (XType Help)

Hi there, I’m currently trying to use XType as a replacement method for the sendKeys command, as a website I use (Discord) doesn’t really function using the other one. Here’s a simple script to test how it works and I had no success:

{
“CreationDate”: “2018-10-27”,
“Commands”: [
{
“Command”: “open”,
“Target”: “hi - Google Search”,
“Value”: “”
},
{
“Command”: “click”,
“Target”: “id=rhscol”,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: “"hi"”,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: “${KEY_ENTER}”,
“Value”: “”
}
]
}

The XType commands do not work at all, the “hi” is not typed and the enter key is not used. Is this not how the XType commands are intended to work? Am I missing something on my end? Thank you!

I believe XType functions as type so you have to use locator for target, and the value would be your text.

Hi, this was the example shown in the XType demo:

{
“CreationDate”: “2018-10-27”,
“Commands”: [
{
“Command”: “store”,
“Target”: “fast”,
“Value”: “!replayspeed”
},
{
“Command”: “open”,
“Target”: “Page Not Found”,
“Value”: “”
},
{
“Command”: “comment”,
“Target”: “Send CTRL+S to open the browser save dialog”,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: “${KEY_CTRL+KEY_S}”,
“Value”: “”
},
{
“Command”: “comment”,
“Target”: "Generate today’s date and time ",
“Value”: “”
},
{
“Command”: “storeEval”,
“Target”: “var d= new Date(); var m=((d.getMonth()+1)<10)?‘0’+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate();”,
“Value”: “mydate”
},
{
“Command”: “storeEval”,
“Target”: “new Date().getHours()+"-" + new Date().getMinutes() + "-" + new Date().getSeconds()”,
“Value”: “mytime”
},
{
“Command”: “echo”,
“Target”: “Today is ${mydate}, and the time is ${mytime}”,
“Value”: “blue”
},
{
“Command”: “comment”,
“Target”: “Wait for the dialog to appear before sending the next keystrokes”,
“Value”: “”
},
{
“Command”: “pause”,
“Target”: “2000”,
“Value”: “”
},
{
“Command”: “comment”,
“Target”: “Send the new file name to the dialog and press ENTER”,
“Value”: “blue”
},
{
“Command”: “XType”,
“Target”: “Page_saved_by_Kantu_${mydate}_${mytime}${KEY_ENTER}”,
“Value”: “”
}
]
}

So I was thinking it was the target that should be what you’re typing? Or am I mistaken? Either way I’ll try it out and see if it works, thank you

Looks like I am wrong. Sorry.
But I can’t copy paste your example. Did you use <code>?

Code here:
<
{
“CreationDate”: “2018-10-27”,
“Commands”: [
{
“Command”: “open”,
“Target”: “Google,
“Value”: “”
},
{
“Command”: “click”,
“Target”: “id=rhscol”,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: ““hi””,
“Value”: “”
},
{
“Command”: “XType”,
“Target”: “${KEY_ENTER}”,
“Value”: “”
}
]
}

Does it work now? Sorry I’m new to this stuff :frowning:

[info]
Executing: | open | hi - Google Search | |
[info]
Executing: | click | id=rhscol | |
[info]
Executing: | XType | hi | |
[info]
Executing: | XType | ${KEY_ENTER} | |
[info]
Macro completed (Runtime 3.73s)

Make sure you’ve installed RealUser XModule!

I’m pretty sure I do have it installed, this is what it executes it fine (no errors shown), but the “hi” does not pop up on google nor is the enter key pressed. So does the code work find on your end?

Thank you so much for your help!

Yes it works perfectly.

Sorry can’t be of any help on the issue.

Nono, thank you so much for testing! At least I now know the problem is on my end! :blush:

Hi! XType itself does not take a target as input, it “stupidly” sends keystrokes to whatever element has the focus. Therefore you must first send an XClick command to the place where the keystrokes should go to, so the right element has the focus. This is the same as if you (as human) first mouse-click in input field before you type.

This info was missing from the docs, I added it now the the XType page.

Thank you so much for clarifying my problem! Appreciate it!

Hi Its very simple to solve this problem, you need to include the command “bringBrowserToForeground” otherwise you Xtype will not work, try to see if works