sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #03121
Re: [Question #159564]: Neither type nor paste works for Java app
Question #159564 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/159564
Status: Open => Answered
RaiMan proposed the following answer:
Ok, I am back and hope I can help ;-)
-- 1. App definitely works
theApp = r"C:\Program Files\Mozilla Firefox\firefox.exe"
version 1:
App.open(theApp)
version 2:
ff = App(theApp)
ff.open()
both versions (I prefer version 2) start Firefox successfully.
-- 2. App.open() return values
in case, App.open() fails for some reason, it returns None (not 0 !)
so this should work:
fullNameOfApp = r"c:\ThinkTDA\ThinkTDA.exe"
tosApp = App.open(fullNameofApp) # would like this to work but it doesn't
if not tosApp:
popup("launch of ThinkTDA failed")
exit(1)
-- 3. make an app start robust
fullNameOfApp = r"c:\ThinkTDA\ThinkTDA.exe"
tosApp = App.open(fullNameofApp) # would like this to work but it doesn't
if not tosApp:
popup("launch of ThinkTDA failed")
exit(1)
while not tosApp.window(): wait(1) # wait for the app window (if it has only one !)
# now the app window should be frontmost
# and ready to accept input
so an additional App.focus() does not make sense. App.open() already
brings it to front.
You might use App.focus() instead of App.open(), which opens the app in
case it is not already running.
--- comment
while not App.focus(): wait(1)
does not make any sense, because there is nothing to wait for: it either
works (app can be started/focused) or not. if not, this is an error.
You might expect, that focus() tells you that the window is ready for
input --- definitely no ;-)
So after an app.focus(), that returns the App object(was successful),
you have to either wait a sufficient time (e.g. 3 seconds) or check by
other means, wether the app window is ready (check titlebar in app
window e.g.).
so in your case the snippet
while not tosApp.focus():
wait(1)
click( ) # force click in text field
the click() might happen, before the app window is ready:
if not tosApp.focus(): exit(1)
wait(2)
click( ) # force click in text field
--- typing text
generally it is not recommended to use type for text, that might contain special characters or characters not on the US qwerty keyboard. use paste() instead which can be combined with raw strings r"".
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.