I am using pywinauto to automate the process of uploading photo, I use Selenuim to click on a button that pops up a window box to select and upload photo. I use Swapy to get the code for setting up automation, but that codes gives an error of "int took too long to convert" I have tried multiple things but failed
I tried To get it using the class names, titles etc but all failed
from pywinauto.application import Application
app = Application().connect(title=u'Open', class_name='#32770')
window = app.Open
static = window.Static
static.ClickInput()
static.type_keys(Name_of_File)
button = window[u'&Open']
button.Click()
I am expecting it to input the name Of file in the windows dialouge box and then click on Open Button to start uploading.
but I get the following error:
return bool(win32functions.IsWindowVisible(handle))
ctypes.ArgumentError: argument 1: <class 'OverflowError'>: int too long
to convert
Related
I am using Python v.3.10.7 and tkinter to open a file dialog, and I believe this to be an issue specific to MacOS (using 13.0 (22A380)), however when I am running the following:
from tkinter import filedialog as fd
file = fd.askopenfilename()
print(file)
The console returns the following when the dialog box is opened:
2022-11-14 20:54:12.497 Python[10059:11543274] +[CATransaction synchronize] called within transaction
Just wondering if there is anyway to stop these from being returned- I have also noticed that when moving the dialog box, the line gets spammed constantly.
I want to automate task in my app using PywinAuto python lib. My goal is to click the open file button and load the file. I had managed to start app and open the file Open Dialog
however am unable to set filename to desire file path.
my code
app = application.Application(backend="uia")
app.start(MyAppPath).connect(title="MyApp",timeout = 5)
app.MyApp.wait('visible')
# click the open button
app.MyApp.Open.click()
app.MyApp.Open.print_control_identifiers()
# Open Dailogue identifiers dump : https://pastebin.com/nt5MpQJx
# tried to set file name , but not worked
app.Open.child_window(title="File name:", control_type="Text").Edit.SetText('C:\myfile.txt')
so any idea how to set the file name.
ok so i have fixed it by changing control_type="Text" to control_type="ComboBox" thought it should be Text but its ComboBox
working code
app = application.Application(backend="uia")
app.start(MyAppPath).connect(title="MyApp",timeout = 5)
app.MyApp.wait('visible')
# click the open button
app.MyApp.Open.click()
app.MyApp.Open.print_control_identifiers()
# Open Dailogue identifiers dump : https://pastebin.com/nt5MpQJx
# tried to set file name , but not worked
app.Open.child_window(title="File name:", control_type="ComboBox").Edit.SetText('C:\myfile.txt')
I wanted to create a metin2 bot, nothing complicated. I am new into that so i just started to look for tutorials on youtube to find something that would lead me to world of coding, how does it work, what language is used to write it ect. So I found a tutorial on youtube about open CV Learn Code By Gaming - OpenCV and thought that's awesome thing to start with.
I got to the point where I can easily detect the names of monsters/metins and wont have any problems in finding the right points to click. After detection started working I thought about automating clicking on the window to farm some items etc. Simple things like clicking e.g 50 pixels below the name to auto attack worked just fine but the problem was that I wanted to make more bots to maximalize farming. So when i started to add more clients I got a problem where e.g you have to hold down SPACE in one window to attack from horse and click on another window which was stopping attacking from horse. So I thought about finding some code that can basically send message directly to window without controlling a mouse or keyboard so you can run multiple bots in one time and each will do perfect meanwhile you can do anything else on pc because your mouse and keyboard aren't used.
Let's start from code I found and none worked for windows in background (even with administrator privileges). Pyautogui doesn't work in background (window has to be in foreground to be clicked on and it controls mouse so there is no point in using that.
From that code I learned that I need to find "window ID" to connect to it and send messages. When i print hWnd it shows the numbers in Terminal and code passes without any fails but does nothing except printing the window ID ( Parent Handle ). Ofc I pip installed pywin32
import win32gui
import win32api
import win32con
def click(x, y):
hWnd = win32gui.FindWindow(None, "Client")
print(hWnd)
lParam = win32api.MAKELONG(x, y)
win32api.SendMessage(hWnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
win32api.SendMessage(hWnd, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, lParam)
click(100, 100)
Than i found another code that looked similar but used different function so first i used
wdname = 'Client'
hwnd = win32gui.FindWindow(None, wdname) # parent handle
print(hwnd)
Which printed me a window ID that i used in parameters in function
def control_click(x, y, handle, button):
l_param = win32api.MAKELONG(x, y)
if button == 'left':
win32gui.PostMessage(handle, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, l_param)
win32gui.PostMessage(handle, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, l_param)
elif button == 'right':
win32gui.PostMessage(handle, win32con.WM_RBUTTONDOWN, 0, l_param)
win32gui.PostMessage(handle, win32con.WM_RBUTTONUP, 0, l_param)
control_click(200, 200, 329570, button ='left')
But it still did nothing but code passed clear
Anyone have any ideas about how to make clicks/keyboard clicks in python on window in background without taking controll of mouse/keyboard? If you have any experience in automating and know better ways to create automation for clicking ect. and want to share it please do. If that can be done in another programming language also share your toughts about that of course if you want to.
Windows 10 x64
Python used: 3.9.2
All codes i found in topics were out of date that s why i am asking for help there. Thanks in advance :)
Object:
automate following process.
1. Open particular web page, fill the information in search box, submit.
2. from search results click on first result and download the PDF
Work done:
To reach to this object I have written a code as first step. The code works fine but opens up download pop up. Till the time I can't get rid of it, I can not automate the process further. Searched for very many solutions. But none has worked.
For instance, This solution is hard for me to understand and I think its more to do with Java then Python. I changed fire fox profile as suggested by many. This dose matches though not exactly same. I haven't tried as there is no much difference. Even this speaks about changing fire fox profile but that doesn't work.
My code is as below
import selenium.webdriver as webdriver
import selenium.webdriver.support.ui as ui
from time import sleep
import time
import wget
from wget import download
import os
#set firefox Profile
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference("browser.download.manager.showAlertOnComplete", False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
#set variable driver to open firefox
driver = webdriver.Firefox(profile)
#set variable webpage to open the expected URL
webpage = r"https://documents.un.org/prod/ods.nsf/home.xsp" # edit me
#set variable to enter in search box
searchterm = "A/HRC/41/23" # edit me
#open the webpage with get command
driver.get(webpage)
#find the element "symbol", insert data and click submit.
symbolBox = driver.find_element_by_id("view:_id1:_id2:txtSymbol")
symbolBox.send_keys(searchterm)
submit = driver.find_element_by_id("view:_id1:_id2:btnRefine")
submit.click()
#list of search results open up and 1st occarance is clicked by coppying its id element
downloadPage = driver.find_element_by_id("view:_id1:_id2:cbMain:_id135:rptResults:0:linkURL")
downloadPage.click()
#change windiows. with sleep time
window_before = driver.window_handles[0]
window_after = driver.window_handles[1]
time.sleep(10)
driver.switch_to.window(window_after)
#the actual download of the pdf page
theDownload = driver.find_element_by_id("download")
theDownload.click()
Please guide.
The "Selections" popup is not a different window/tab, it's just an HTML popup. You can tell this because if you right click on the dialog, you will see the normal context menu. You just need to make your "Language" and "File type(s)" selections and click the "Download selected" button.
I want to get the text of the pop up window in the attached image. Right now I am using selenium in python for getting those text value. Following is my code-
time.sleep(LOADING_TIME)
alert = driver.switch_to.alert
print(alert.text())
But, when I am doing that I am getting following error -
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
(Session info: chrome=69.0.3497.81)
(Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.13.6 x86_64)
Can anyone tell me what I am doing wrong?
Note that: I am using chrome driver for initializing selenium driver and the example I have added here can be found whenever you want to add an extension to your chrome browser.
The problem is that driver.switch_to.alert is a function.
Change it like so:
driver = webdriver.Chrome()
driver.get(your_url)
alert = driver.switch_to_alert()
alert.accept()
# Eventually do anything else.
driver.close()
[EDIT]
Since it seems that selenium doesn't recognize the dialog, you could use pywinauto module: to get the dialog and interact with it.
from pywinauto import Application
driver_handle = driver.current_window_handle # get driver window handle
app = Application().connect(handle = driver_handle) # initialize app
dialog = pywinauto.app.top_window_() # select the dialog
dlg.control.Addextension.Click() # click on "Add extension" button