Jump to content

Python and AutoIt


rsvore
 Share

Recommended Posts

I'll say I'm new to Python and AutoIt.

I created a Python script using Selenium. The Python scripts works fine. Now I'm looking at calling an AutoIt script that clicks the save a file dialog box.

I added autoit.Run("SelectFilenetSavedialogue3.au3") in my Python script.

I ran the Python script and everything worked, I then ran the script again (because I could believe I got it to work the first time) and the second time the AudIt script did not select the Save button as in the first time I ran the Python script.

Now, I may not be calling the Audit script right or the state of Audit is lost, just not sure why it would work once then not again. Any thought? Thanks

Link to comment
Share on other sites

Here is my AutoIt script:

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1

Author: myName

Script Function:

Template AutoIt script.

#ce ----------------------------------------------------------------------------

$csnNumber = "Opening " & "201227510028031" & ".tif"

Func Au3RecordSetup()

Opt('WinWaitDelay',100)

Opt('WinDetectHiddenText',1)

Opt('MouseCoordMode',0)

EndFunc

Func WinWaitActivate($title,$text,$timeout=0)

WinWait($title,$text,$timeout)

If Not WinActive($title,$text) Then WinActivate($title,$text)

WinWaitActive($title,$text,$timeout)

EndFunc

AU3RecordSetup()

WinWaitActivate($csnNumber,"")

MouseClick("left",268,256,1)

Link to comment
Share on other sites

Are you activating the window you are waiting for, manually?

Are you sure the title is correct?

EDIT:

And what is going wrong?

Does the script exit or just sit waiting for the window?

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Well, when the Python script runs it opens Firefox and navigates to a particular page then selects an icon on the screen to download a file. The "Save" dialog box pops up and this is where I call the AutoIt file to select the save button in the dialog box. The title in the dialog box is "Opening 201227510028031.tif". So, the AutoIt finds it and clicks the save button.The python script finishes successfully. I did add a time.sleep(10) in the python script to give AutoIt a chance to work. But again Autoit doesn't click the save button every time.

Here is a snip-it of the Python script where I call AutoIt :

driver.find_element_by_css_selector("img[alt="Open:"]").click()

""" add AutoIt here to download first file """

autoit.Run("SelectFilenetSavedialogue2.au3")

time.sleep(10)

Link to comment
Share on other sites

I tried this in Python to click on the save button, but it doesn't work.

pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'Opening 1350672610_address_book.png', class_name='MozillaDialogClass')[0]
window = pwa_app.window_(handle=w_handle)
window.SetFocus()
window.Click()
window['OK'].Click()
""" window.ClickInput('OK') """
""" window.PressMouseInput()"""
window.PressMouse()
Link to comment
Share on other sites

I tried this in Python to click on the save button, but it doesn't work.

pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'Opening 1350672610_address_book.png', class_name='MozillaDialogClass')[0]
window = pwa_app.window_(handle=w_handle)
window.SetFocus()
window.Click()
window['OK'].Click()
""" window.ClickInput('OK') """
""" window.PressMouseInput()"""
window.PressMouse()

perhaps pywingui help for this
Link to comment
Share on other sites

Sure, how?

I would rather not have to use the AutoIt script and just do it in Python if possible. Thanks

import win32api, win32con
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click(10,10)

I am a wx.python user :D

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Thanks Universalist, I'll give this a try this morning. What does click(10,10) mean/do.

I know this is not a Python forum but: I named the function to save_click becaus I was getting a problem with a .click I had in another function. So I call the function self.save_click(269,258) and give it two arguments. But I get the error that the click(10,10) is a global name and needs to be defined.

self.save_click(269,258)

def save_click(self,x,y):
        win32api.SetCursorPos((x,y))
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
        click(10,10)
Edited by rsvore
Link to comment
Share on other sites

I have it figured out in Python.

I called the save_click function by passing in two arguments self.save_click(570,540). I had used the coordinates from AutoIt but they were missing the OK button after some investigation I found the new coordinates to use. Now, AutoIt may work with the new coordinates but for now I'm keeping the script all Python. To get the right coordinates of the OK button I screen captured the screen scrape that showed the dialog box within the Firefox browser pasted it in Paint.net and found the x and y from the ruler. I was using coordinates of only the dialog box which didn't work from AutoIt.

Here is the Python function:

def save_click(self,x,y):
        win32api.SetCursorPos((x,y))
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
Link to comment
Share on other sites

If you want / have to use Python for most of your code, and mouse clicks are not enough, then you could have a look at pywinauto or try to create a ctypes wrapper for AutoItX.dll.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I have it figured out in Python.

I called the save_click function by passing in two arguments self.save_click(570,540). I had used the coordinates from AutoIt but they were missing the OK button after some investigation I found the new coordinates to use. Now, AutoIt may work with the new coordinates but for now I'm keeping the script all Python. To get the right coordinates of the OK button I screen captured the screen scrape that showed the dialog box within the Firefox browser pasted it in Paint.net and found the x and y from the ruler. I was using coordinates of only the dialog box which didn't work from AutoIt.

Here is the Python function:

def save_click(self,x,y):
     win32api.SetCursorPos((x,y))
     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
     win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

Yeah sorry but i wrote the code here didn't copied it.

Edit: Just for the story Universalist is my tag not my name, ileandros is my name :D

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...