I am trying to open a browser and clear the contents in URL and type new URL. (Each script has different url and need to change it) For this, I am clicking on URL which highlights the current url and then TypeText deleteKey.
However, this only randomly works and does not give consistent results. I tried different techniques like waiting for a while to browser completely load , changing the hotspot position to click and all… but this issue is still seen. (Sometimes part of the url is deleted, sometimes single letter of url is deleted. No consistency) sometimes it occurs and sometimes it does not. Can someone suggest any idea how to implement this.
This is almost certainly some kind of timing issue, with the page in the browser stealing focus or something like that. One thing that might work is, rather than deleting what’s in the location field, just telling the browser that you want to go somewhere else by using the “Open Location” keyboard shortcut. So, if you’re running against a Mac, for example, you’d use this code (FireFox, Safari, and Chrome all use the same shortcut):
TypeText commandKey, "l"
TypeText <url> & return
You shouldn’t have to worry about deleting anything, just start typing.
This works really cool for me. Should have figured out this shortcut earlier. Thanks much.
Thanks very much for this. i was looking for some code for this particular issue. thanks again!
In my testing I do lot of work with text fields. I have written some basic functions for select all, copy, paste, and delete. It allows me to quickly manipulate text field data.
to handle copy
TypeText controlKey, “c”
to handle paste
TypeText controlKey, “v”
to handle selectAll
TypeText controlKey, “a”
to handle clearField
I put these in a utility script and just call them whenever I need to manipulate text field data. Note: You will have to have selectAll below clearField if they are in the same script, since clearField calls selectAll.
I think creating your own commands like this is a great idea. An additional advantage of this approach if you’re testing software on different platforms is that you can create alternate versions of these commands for each platform. For example on Windows you’ll use TypeText ControlKey,“c” to do Copy, but on Mac it will be TypeText CommandKey,“c” instead. Just select the set of utility handlers for the platform you’re testing and your test scripts that use these functions will ‘just work’.
Actually, in SenseTalk it doesn’t matter what order the handlers are in within a script. You can call other handlers wherever they appear.
What does matter is that all of your handler definitions appear after any script code that is not inside a handler declaration. So you can’t start out by defining some handlers and then have code that you want to run when the script is called:
put "hello world"
// handler code
// handler code
put "hello world"
Is this also the case for functions that have a return? I have had times where I would call a returning function from within a handler, and it wouldn’t find the function until I moved it lower in the code than the handler that called it.
I could be wrong on this, but I’m 99% sure I’ve had to move one handler below another to make them work correctly.
Probably there was something else going on for you at the time that gave you that impression. There is no dependency on the order of handlers in a script, except as Matt pointed out that the initial handler (code outside of other handlers) must be at the top of the script or it will be ignored.