← Back to team overview

sikuli-driver team mailing list archive

[Question #237595]: [1.0.1] help using App.focus() from inside a class

 

New question #237595 on Sikuli:
https://answers.launchpad.net/sikuli/+question/237595

im trying to make a simple controller for ie9 that i can use for testing and parsing information from webpages. the idea is that i would use the controller class to control a browser window and call webpage classes that have methods for parsing info from the webpage source html. i have 2 methods in the class, getAdr and getSrc. getAdr uses ctrl-l,ctrl-c to get the text in the address bar. getSrc uses alt-v,c to view source, copies the text and then closes the source window. they both work individually. but if i call getAdr and then getSrc, the focus doesnt change and the browser window gets closed instead of opening the source window. i suspect it has something to do with the way i defined the class and/or methods, because i have functions that do exactly the same thing and they work as expected.
here is the code:

from sikuli import *
import re
from org.sikuli.basics.proxies import Vision
Vision.setParameter("MinTargetSize",6)
mmd = Settings.MoveMouseDelay
Settings.MoveMouseDelay = 0.01

class Gui(object):
    '''base class'''
class GuiElem(object):
    '''base class'''
class Window(Gui):
    '''base class'''
class Browser(Window):
    '''base class for ie9 controller'''
    def getSource(self):
        '''copies source from the active tab to the system clipboard.
        uses keyboard shortcuts internally.'''
        raise NotImplementedError
    def open(self):
        raise NotImplementedError
    def switchTo(self):
        raise NotImplementedError
    def close(self):
        raise NotImplementedError
class Ie9(Browser):
    '''controller for Ie9. internally uses keyboard shortcuts to control the browser.'''
    def __init__(self):
        '''initialize a new Ie9 obj'''
        self.inst = App(' - Windows Internet Explorer')
    def getAdr(self):
        '''stores address bar contents using system clipboard'''
        self.inst.focus()
        type('l',KeyModifier.CTRL)
        type('c',KeyModifier.CTRL)
        self.adrVal = Env.getClipboard()
        text = open(r'adr.txt', 'r+') #for testing
        print >> text, self.adrVal     #for testing
        text.close()                             #for testing
        return self.adrVal
    def getSrc(self):
        '''copy source from the active tab using system clipboard.
        stores the source in a Page obj'''
        self.inst.focus()
        type('v',KeyModifier.ALT)
        type('c')
        wait(0.4)
        type('a',KeyModifier.CTRL)
        type('c',KeyModifier.CTRL)
        wait(0.4)
        type('w',KeyModifier.CTRL)
        self.src = Env.getClipboard()
        text = open(r'src.txt', 'r+') #for testing
        print >> text, self.src          #for testing
        text.close()                            #for testing
        return self.src
if __name__ == '__main__':
    browser = Ie9()
    browser.getAdr()
    browser.getSrc()

any help or suggestions would be greatly appreciated.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.