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')
Related
for reference this is all using Pyqt5 and Python 3.6:
I've got a QStandardItemModel that is built from QStandardItems that are strings of the items in a zip (the model displays all the contents of a zipfile). I went with this choice as I can not cache the files locally, and my research shows that QFileSystemModel can not work on archives unless I unpack at least temporarily.
All items in the QStandardItemModel end in the correct extension for the file (.csv,.txt,ect), and I need to display the icon a user would see if they were looking at the file in windows explorer, however show it in the qtreeview (a user seeing content.csv should also see the icon for excel). On that note, this application is only running on windows.
How can I pull the extensions default system file icon, and set it during my setting of these items? Would I have to manually download the icons for my known file types and do this, or does the system store it somewhere I can access?
Here's some basic code of how I build and display the model and treeview:
self.zip_model = QtGui.QStandardItemModel()
# My Computer directory explorer
self.tree_zip = QTreeView()
self.tree_zip.setModel(self.zip_model)
def build_zip_model(self,current_directory):
self.zip_model.clear()
with zipfile.ZipFile(current_directory) as zip_file:
for item in zip_file.namelist():
model_item = QtGui.QStandardItem(item)
self.zip_model.appendRow(model_item)
You can use QFileIconProvider:
def build_zip_model(self, current_directory):
iconProvider = QtWidgets.QFileIconProvider()
self.zip_model.clear()
with zipfile.ZipFile(current_directory) as zip_file:
for item in zip_file.namelist():
icon = iconProvider.icon(QtCore.QFileInfo(item))
model_item = QtGui.QStandardItem(icon, item)
self.zip_model.appendRow(model_item)
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 have written a small script to open a powerpoint file, save it as PDF and close powerpoint. It looks like the command ppSaveAsPDF is not getting recognized.
It says NameError: name 'ppSaveAsPDF' is not defined
Could someone please tell me why I am unable to save the file as pdf and close the application ?
Moreover when I remove the ppSaveAsPDF command it saves a PDF file but it is corrupt and I am unable to open it.
I have included my code below:
import win32com.client, sys
FILENAME = "C:\\Users\\Swaroop\\Desktop\\Scripts\\Test.pptx"
APPLICATION = win32com.client.Dispatch("PowerPoint.Application")
PRESENTATION = APPLICATION.Presentations.Open(FILENAME, ReadOnly= False)
PRESENTATION.SaveAs("C:\\Users\\Swaroop\\Desktop\\Output.pdf", ppSaveAsPDF)
APPLICATION.Quit()
I have come up with a work around for this, instead of using ppSaveAsPDF, I am using its constant value which is "32" and setting both PRESENTATION AND APPLICATION to NONE actually closes the powerpoint. Here is the updated code.
import win32com.client, sys
FILENAME = "C:\\Users\\Swaroop\\Desktop\\Scripts\\Test.pptx"
APPLICATION = win32com.client.Dispatch("PowerPoint.Application")
PRESENTATION = APPLICATION.Presentations.Open(FILENAME, ReadOnly= False)
PRESENTATION.SaveAs("C:\\Users\\Swaroop\\Desktop\\Output.pdf", 32)
APPLICATION.Quit()
PRESENTATION = None
APPLICATION = None
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
I can launch the default browser (chrome) with
call WShell.Run("http://www.google.com", 1, false)
but if I try
call WShell.Run("http://www.google.com", 1, true)
I get an error:
"unable to wait for process"
How can I launch a browser (could be IE or chrome) in a new process and wait for that process to exit.
See this question for "why?"
2019. VBS using HP UFT (QTP)
In HP UFT, I found few ways to run the browser via VBS.
My favorite is SystemUtil.Run.
1.SystemUtil.Run
strURL = "www.google.com"
str_NavigateTo = "https://chesstempo.com/chess-tactics.html#5"
int_mode_Maximized = 3
SystemUtil.Run "iexplore.exe",strURL, , ,3
SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE", str_NavigateTo,"C:\Program Files\Internet Explorer", ,int_mode_Maximized
Where Mode & Description
'0 Hides the window and activates another window.
'1 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size
and position. Specify this flag when displaying the window for the
first time.
'2 Activates the window and displays it as a minimized window.
'3 - Activates the window and displays it as a maximized window.
'4 Displays the window in its most recent size and position. The active window remains active.
'5 Activates the window and displays it in its current size and position.
'6 Minimizes the specified window and activates
the next top-level window in the Z order.
'7 Displays the window as a minimized window. The active window remains active.
'8 Displays the window in its current state. The active window remains active.
'9 Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size
and position. Specify this flag when restoring a minimized window.
'10 Sets the show-state based on the state of the program that started the application.
*Extra detailed descriptions of the SystemUtil parameters can be found here:
SystemUtil.Run
2. InvokeApplication
InvokeApplication "C://Program Files/Internet Explorer/IEXPLORE.EXE http://www.wp.pl"
3. VBScript via WScript.shell
If the path to your executable contains spaces, use Chr(34) to ensure the path is contained within double quotes.
Dim oShellSet oShell = CreateObject ("Wscript.shell")'
'Example 1 - run a batch file:
oShell.run "F://jdk1.3.1/demo/jfc/SwingSet2.bat"
'Example 2 - run a Java jar file:
oShell.run "java -jar F://jdk1.3.1/demo/jfc/SwingSet2/SwingSet2.jar"
'Example 3 - launch Internet Explorer:
oShell.Run Chr(34) & "C://Program Files/Internet Explorer/IEXPLORE.EXE" & Chr(34)
Set oShell = Nothing
4. IE Automation Object Model
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate "http://www.google.com/"
oIE.Visible = True
......
Set oIE = Nothing
5. Use the Windows \ Start \ Run dialog.
Add the Windows Start button to the Object Repository using the “Add Objects” button in Object Repository dialog.
Open the Run dialog (Start -> Run), and learn the “Open” edit field and the “OK” button into the Object Repository.
Switch to the Expert View, and manually add the lines to open the Run dialog.
Example:
Window("Window").WinButton("Button").ClickWindow("Window").Type("R")
Manually enter the lines to enter the information to launch the application, and click the “OK” button of the Run dialog.
Example:
Dialog("Run").WinEdit("Open:").Type "C://Windows/System32/notepad.exe"
Dialog("Run").WinButton("OK").Click
WebUtil Object
In UFT 14.01 update, HPE introduced two new methods for WebUtil Object. LaunchBrowser and LaunchMobileBrowserWithID
WebUtil.LaunchBrowser Browser, [device_model, device_manufacturer, device_ostype, device_osversion]
WebUtil.LaunchBrowser "MOBILE_CHROME", "Apple_5s", "Apple", "IOS", "10.1.3"
WebUtil.LaunchMobileBrowserWithID Browser, device_ostype, device_id
WebUtil.LaunchMobileBrowserWithID "MOBILE_CHROME", "IOS", "02"
Source with more info: 6 ways to launch your application
I've found one way using --user-data-dir=/some/directory:
call Shell.Run("""%userprofile%\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"" --user-data-dir=/some/directory "http://www.google.com", 1, true)
I used this command to open the Google home page:
call Systemutil.Run("http:www.google.com, 1, true)
It opened Google home page without any errors.