sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #29496
Re: [Question #258406]: Confused about Jython example
Question #258406 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/258406
Status: Open => Answered
RaiMan proposed the following answer:
Where did you get the example?
Depending on your Firefox (FF) "usage history" this simple approach might not work, because FF might have a bunch of invisible windows and the main window you see might not be window(0), which is returned by window().
Currently using window() does not check, wether the region representing the window is visible on the screen.
I recently setup a generic bunch of functions, that allow, to start FF
in a repeatable manner, get the only main window, navigate to an url and
wait for the webpage to be ready based on a visual content, that should
be there.
def ffStart(ffN = ffName, ffLoc = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"):
global ffName
ffName = ffN
ff = App.open(ffLoc)
return ffGetWindow(App(ffName))
def ffGetWindow(ff = None):
global ffName
ffWin = None
if not ff:
return App(ffName).window(0)
for i in range(3):
if ff.window(0) == None:
wait(1)
continue
for i in range(100):
ffWin = ff.window(i)
if ffWin == None:
break
if ffWin.w < 200:
continue
break
break
return ffWin
def ffStop():
global ffName
if ffGetWindow():
ff = App.focus(ffName)
while ffGetWindow(ff):
ff = App.focus(ffName)
type("w", Key.CTRL)
wait(1)
App.close(ffName)
def ffGoto(url, waitFor = None, waitTime = 10):
global ffName
ff = App.focus(ffName)
ffWin = ffGetWindow(ff)
if ffWin:
type("l", Key.CTRL)
wait(0.5)
paste(url)
type(Key.ENTER)
if waitFor:
if not ffWin.exists(waitFor, waitTime):
return None
return ffWin.getLastMatch()
return ffWin
--- usage
ffStop() # stop a current FF session to get a clean base
ffWin = ffStart() # start FF and get the main window
found = ffGoto(aURL, imgURLReady) # open the given url and wait for the image imgURLReady (default 10 secs)
if not found:
print "could not open url"
exit(1)
found.highlight(2)
# do something
ffStop() # optional
go through the code, to understand the things behind the scene and usage
options
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.