[1.0.1] help using App.focus() from inside a class
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.
Vision.
mmd = Settings.
Settings.
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):
self.inst = App(' - Windows Internet Explorer')
def getAdr(self):
'''stores address bar contents using system clipboard'''
self.adrVal = Env.getClipboard()
text = open(r'adr.txt', 'r+') #for testing
print >> text, self.adrVal #for testing
return self.adrVal
def getSrc(self):
'''copy source from the active tab using system clipboard.
stores the source in a Page obj'''
type('c')
wait(0.4)
wait(0.4)
self.src = Env.getClipboard()
text = open(r'src.txt', 'r+') #for testing
print >> text, self.src #for testing
return self.src
if __name__ == '__main__':
browser = Ie9()
browser.
browser.
any help or suggestions would be greatly appreciated.
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask rob for more information if necessary.