jacexh / pyautoit

Python binding for AutoItX3.dll
MIT License
269 stars 74 forks source link

How to go to next action if some condition fails in PyAutoit? #9

Closed balup34 closed 7 years ago

balup34 commented 8 years ago

I am using the following pyautoit code to automate the windows app installation.

My requirement is , Script should wait for 30 seconds for a window to appear. If window appears it should raise exception. Else it should go to next action.

Following code raises exception when the window appears. But when window NOT appears its not going to next step. Its throws "AutoItError: timeout on wait for activate window". I don't want to get through this error. Simply its should go to next action.

Code :

if autoit.win_wait_active("[CLASS:TESTINH]", 30) == 0:
    raise Exception("Env is DOWN...!!!")
else:    
    autoit.send("{TAB}")
    autoit.send("{ENTER}")    

Any idea please?

Aareon commented 8 years ago

Python has a built-in exception catch function. Use that to ignore any exceptions. Sorry, I have no way to provide any source as I'm on a phone.

balup34 commented 8 years ago

@Aareon Thanks... Actually If you see my code... I am using "raise Exception()". This is python inbuilt function. still I am seeing the issue.

Sorry If I misunderstood your comment. Please guide how to fix this code.

Aareon commented 8 years ago

I may be mistaken, but you can use a conditional if else statement to handle any exceptions other than what you're after.