watir-webdriver functions do not execute as a script but works on the interactive ruby shell - firefox

I am trying to write automated scripts for a web application using watir. There is a slider in the UI, which has a range from 1 to 11. It is a horizontal div. So, if you press the right arrow key, the number increments by 1, and if you press a left arrow key the number decrements. My problem is when I try to execute the following statements in irb individually, the send_keys function works fine, but as soon as I move it to a ruby script, it does not execute the send_keys.
assert($b.div(:class, "position").text == "2")
$b.div(:class, "scroll").wait_until_present
$b.div(:class, "scroll").click
$b.div(:class, "scroll").send_keys(:arrow_right)
assert($b.div(:class, "position").text == "3")
The send_keys(:arrow_right) works if I run separately in irb. When trying to run through a script file, it does not give me any error and remains on the same number, and it just says "Failed assertion, no message given."
The b.div(:class, "scroll").click is to activate the div on which the the right arrow key is to be pressed.
I'm using watir-webdriver 0.6.2, Firefox 18.0.2, Windows 7 64-bit

As you mentioned b.div(:class, "scroll").click is to activate the div on which the key is to be pressed,
There might be possibilities that this is taking a while to activate the div, and when you are doing that in IRB that is getting proper time to load as it takes time to execute another line, but when you are doing that in script and executing you are performing send_keys action immediately after clicking on the div, and execution not getting proper time to activate that Div.
Try to give a pause/delay in your script for a while and then try to perform send_keys.
To give a pause/delay you can use sleep(time_period)

Related

(NO mystery:) How Automator transfers "invisible" information to Script-Editor

( I have been pushed to an obvious answer to my "Mystery" from a friendly member here.
I feel a little ashamed not to have found this solution myself, but will leave this posting online if there aren't too many irritated folks around. Maybe someone else can learn from this … apologies to every "know-it-alls"!)
I have recorded these actions with Automator:
– Cmd-tab to bring TextEdit to front (must have some lines typed)
– Pressed left arrow 7 times using shift down
– Stopped the recording
Next I selected and copied (Cmd-c) all action icons in Automator's "Record my actions" window.
I switched to Script-Editor and pasted (Cmd-v) them into a new window.
Then, I repeated above recording with 3 times UP arrow and copied icons into another new window.
I took only the two "set uiScript to …" lines and appended them in the first script.
THEY READ IDENTICAL:
set uiScript to "keystroke \"\t\" using command down"
my doWithTimeout(uiScript)
set uiScript to "keystroke \"\" using shift down" -- 7 times left-arrow
my doWithTimeout(uiScript)
set uiScript to "keystroke \"\" using shift down" -- 3 times up-arrow
my doWithTimeout(uiScript)
on doWithTimeout(uiScript)
set endDate to (current date)
repeat
try
run script "tell application \"System Events\"\n" & uiScript & "\nend tell"
exit repeat
end try
end repeat
end doWithTimeout
(To make resulting code more readable I omitted error code and "delays".)
Now, if I disable one of the "keystroke" lines (=> --my doWith…) the script somehow knows that it either has to do Shift-leftArrow 7 times OR Shift-upArrow 3 times.
I tried this after computer restart, even copied the code from this web page and pasted it into a new Script Editor window – it still knew what to do!
HOW CAN THAT BE ???
My only idea is: there must be some internal Applescript database that recognises content even if copied/pasted.
Does anybody know ?
Only if I re-write the code identically will there happen NOTHING – until I copy the first line of either recording ("set uiScript to …"). So the information must be linked to this first line somehow.
(BTW: first two lines that bring TextEdit –or, e.g. a Finder window– to the front work only from opened Script Editor; you have to bring TextEdit to the front yourself, if you start the saved-as-program script from Script-Editor's menu icon subfolder. Nevertheless the script won't work without them…)
It "knows" because the keystrokes are in the string - keystrokes using control type keys (such as arrow keys) just don’t have a text representation, so they wind up being invisible. Some text editors such as BBEdit can show these invisible characters, but they don’t show up in the Script Editor.
Apple has obviously made Automator's Watch Me Do action able to capture some of these control keys in a string, but for the rest of us it is more difficult, since the control keys will actually perform their function when pressed. If you need to use these kinds of keys, the key code command can be used, since it refers to the actual keyboard key, for example:
tell application "System Events"
repeat 3 times
key code 126 using shift down -- up arrow
end repeat
end tell
As the answer is quite simple but may still be interesting to some, I'll explain it shortly:
red_menace (in his comment above) pointed out that strings may contain invisible elements (like arrow keys), therefore I next checked the obvious:
If you "cursor-walk" along the "set uiScript …" strings the cursor will actually "pause" for 7 or 3 "steps" respectively on its way.
I hadn't thought/heard of any "invisible" string-chars (apart from obvious ones in Word etc.).

How to setup Toggle Key to display the shell script output during execution?

In my team they have asked me to create a shell script with toggle key option to display the command output/errors when a arrow key is pressed. And it need to hide the output when the same arrow key is pressed. Is there a way we can achieve this using a shell script?
I don't have a solution yet but the script which we are using now is throwing so many output and its making the screen loaded without so many lines of std output/errors during execution. And we would like to hide the output using the toggle key and when needed if we press a key it needs to display the output during execution.
No idea on how to start with this. Need some idea or thoughts on how to achieve this?
Expected:
Shrink the output using toggle key (say for example UP arrow key) and when needed if we press the same UP arrow key it need to display the output again.
Actual:
No code available as of now to do this function.

Completion popup closes after pressing Enter twice

I'm using Qt Creator 3.1.1 with FakeVim mode enabled.
When the completion popup appears with the desired function already as the first one, I have to press Enter twice in order to insert text. The same thing happens when I want to insert more letters before hitting Enter. I have to press first key twice, than everything goes as expected (following keys require single presses, Enter too).
ex. I entered avform and the popup appeared. If I want the first tooltip AVFormatContext i press Enter twice. If I want avformat_smthing I need to press aaform_ cause the first a will like change mode back to insert (but not really as I'm still in INSERT mode).
I wonder if anybody stumbled upon similar problem/inconvenience, and what can I do to change QtCreator behavior.
It seems like it's a known bug, and it hasn't been fixed yet. It only appears in newer versions of Qt-creator (>2.8.1). Partial fix is to disable autocompletion or unmark Pass keys in insert mode but both options have side effects (ex.Ctrl+N opens completion popup, but the text doesn't get inserted).
Link to: Issue on BugTracker for curious.

{ENTER} Keystroke iMacros for Firefox

I've found a decent amount of code to replicate a backspace or the enter key (DS, WINCLICK, etc.) -- but none of them work on iMacros for Firefox (Version 8.3.0). Is there anything I can do with this version?
My code is perfect, I just need an 'enter' keystroke or even a backspace after one of the lines to make the dropdown I need populate.
Can anybody help?
Thanks!
Then use Experimental recording and click on the place you want to type. Then press Enter.
http://prntscr.com/13dnw9
You can also check and un acheck the Favor element IDs ... option do get different ways of recording an EVENT command.

Mac-Automator, How to pipe the output of a shell script to a GUI text box

The problem I face is this:
I would like to have in a context menu (when i right-click on a folder) an action to be executed and display the output to the user, inside, let's say, a text area window with a vertical scrolling bar. Suppose, that the action is just a shell script that executes a "find" command inside the given directory, searching for a specified pattern.
I have managed to implement it, up to this point, using Automator. What I cannot do is to pipe the output in a synchronous fashion (what is meant by "synchronous" is to have the output print to the user when is produced by the "find" command, and not after the command has finished) in a GUI.
I have spent sometime searching on this and I have come to the conclusion that XCode and Interface Builder have to be put into the play? Am I on the right track? Is there a straightforward and simple way in succeeding in this without having to dig into this framework?
Thank you very much,
Babis
You can have the shell script throw a dialog when it gets the result using http://cocoadialog.sourceforge.net/

Resources