Problem with InternetExplorer 9 app.focus

Asked by Joost

I'm trying to keep one instance of the browser open. With firefox, this works perfectly, but Internet Explorer 9 just opens new windows, and I can't check how many windows are open.

[log] App.focus InternetExplorer(0) #0
[error] App.focus failed: InternetExplorer not found

       app = App(name)
        if not app.window(): # no window found - browser is not open / Does not work with IE
            print "## Opening new browser window ##"
            app.open(browserExecutable)
            wait(3)

            # maximize the screen
            type(Key.UP, KEY_WIN)
        app.focus() # this does not work with IE

So app.focus() throws errors, and app.window() returns nothing, even when there is a window open. Is this a known issue?

I'm using windows 7, 64 bit professional.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Joost
Solved:
Last query:
Last reply:
Revision history for this message
Bekir Dogru (bekirdogru) said :
#1

is
self.app.open(self.browserExecutable)
working?

Revision history for this message
Joost (joostvanpinxten) said :
#2

I've encapsulated the code above in a class, so that is better re-usable. I didn't modify it properly for this question.

So, to answer your question: Yes, it does. As it opens another IE window, I know it works. (i just use 'c:\\Program Files (x86)\\Internet Explorer\\iexplore.exe')

Revision history for this message
Bekir Dogru (bekirdogru) said :
#3

I am asking just in case: in your error code it is written InternetExplorer not Internet Explorer, you may forget to write that space between Internet and Explorer words, this may cause the problem?

Revision history for this message
Joost (joostvanpinxten) said :
#4

Thank you, very observing. This was the fix that I was looking for

I was using this name under the the assumption that it would register it internally. But it seems that the name must _always_ be found in the window title?

It says in the documentation:

"...create an App instance and use the instance methods afterwards (e.g. myApp = App("application-identifier") and then later on myApp.open())..."

And I read this as: you can choose your own application-identifier. But it seems that the application-identifier must be a term in one of the window's titles? This may be cleared up in the documentation, to avoid confusion.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

The App class's internal implementation is system dependent and same goes for the behavior.

On Windows, it is best to use
App.open(path_to_executable) # which is a class method (Java static).

and then define an App object based on the window title (or significant parts of it to group windows)
browser = App("Internet Explorer") # just as Bekir suggested

So in your case, your coding could be: (not sure about indentation)

name = "Internet Explorer" # somewhere, somehow before usage
browserExecutable = 'c:\\Program Files (x86)\\Internet Explorer\\iexplore.exe'
        app = App(name)
        if not app.window(): # no window found - browser is not open
            print "## Opening new browser window ##"
            App.open(browserExecutable) # use static class method
            wait(3)
            # while not app.window(): wait(1) # would be more general
            # maximize the screen
            type(Key.UP, KEY_WIN)
        else: app.focus() # only needed if already open