3

When I click a new window button, its always opens in background in Windows 7 64 bit OS.

For my automation task, I need to bring that window to foreground.

Following is my pyautoit code:

autoit.send("{TAB 2}")
sleep(3)
autoit.send("{ENTER}") # After this step new window appears in background
Wnd = autoit.win_wait("[CLASS:#32770]", 15) 
autoit.win_activate(Wnd)        
sleep(5)
autoit.send("{ENTER}")

I have tried win_wait and win_activate as shown below:

Wnd = autoit.win_wait("[CLASS:#32770]", 15) 
autoit.win_activate(Wnd)

But I am getting following error:

WindowsError: exception: access violation reading 0x00000001

Then I tried the "regedit" option as shown in following URL :

http://ask.brothersoft.com/when-i-open-a-program-window-sometimes-it-opens-in-the-background-instead-of-the-foreground-253939.html

But no use. Still I am seeing the same issue.

Could any one help me to fix this issue please?

rcubefather
  • 1,534
  • 6
  • 25
  • 49
  • Try the different functions from Autoit directly. isHandle Winactivate and so on. If that works, then use that one in your py script. – Xenobiologist Oct 08 '15 at 09:46

1 Answers1

1

I would do it like this:

AutoIt.Send("{TAB 2}")
Sleep(3)
AutoIt.Send("{ENTER}")
AutoIt.WinWaitActive("[CLASS:#32770]", 15)
AutoIt.WinActivate("[CLASS:#32770]")
Sleep(5)
AutoIt.Send("{ENTER}")

Or use Alt-Tabs

AutoIt.Send("{TAB 2}")
Sleep(3)
AutoIt.Send("{ENTER}")
Sleep(1)
AutoIt.Send("{ALT DOWN}")
AutoIt.Send("{TAB}")
AutoIt.Send("{ALT UP}")
Sleep(5)
AutoIt.Send("{ENTER}")

Also don't use the CLASS, just use the name of the window like:

AutoIt.WinWaitActive("Setup", 15)
IkeRoyle
  • 457
  • 4
  • 13
  • Thanks for your answer. I have tried the same. But the window appears in background. Unable bring this front. Error : AutoItError: timeout on wait for activate window. Any idea to fix this please? – rcubefather Oct 09 '15 at 07:40
  • Did you try useing the windowname rather than the CLASS? And can you activate the window manually? – IkeRoyle Oct 09 '15 at 07:49
  • Yes. I am able to activate the window manually. And I have tried with Window name also. I am unable to bring it front. – rcubefather Oct 09 '15 at 16:33
  • Hmm, can you bring it in foreground manually or with a keycombo like ALT-TAB? – IkeRoyle Oct 12 '15 at 06:45
  • Yes I am able to bring it foreground manually. And also with ALT-TAB – rcubefather Oct 12 '15 at 17:15
  • Sorry for my irregular awnsers. Ok my soloution would be to send ALT TAB als buttons to your PC. I'll edit the answer. – IkeRoyle Oct 13 '15 at 07:48