How do I handle the system windows with Python on Windows OS? - python

With Selenium Webdriver, I have to upload some files on a website but since the pop-up window for browsing the file location is handled by the operating system and not the browser, I cannot automate that part with Selenium.
So I want to know which framework or module I need to use to work with system windows of Windows OS. Can tkInter or wxPython be used for this?
My script will be used on Windows 7, 8 & 10.

Actually, you can upload files without interacting with upload prompt pop-ups.
To be able to handle file upload with selenium you should send path to file to appropriate input field without clicking on "Upload" button. Try following:
path_to_file = 'C:\\Files\\path\\to\\file' # use your specific path instead
driver.find_element_by_xpath('//input[#type="file"]').send_keys(path_to_file)
P.S. Let me know if this code doesn't work as you expect

You can call autoit3 framework from Python even to open the File Open dialog and fill in the values and press OK or do whatever with the windows. Autoit3 has a dll that can be loaded and called using ctypes. That's what I did in one or 2 projects.
If I understand your question correctly, wxpython or tk won't help you. They can be used to make the windowed UI, not to control other programs.

Related

cannot open python script by double clicking

i have searched on multiple forums and looks like others met similar issues but I haven't read a straightforward explanation yet. what I am trying to do is to simply open my python script by double clicking it. it used to work, but not anymore. my python scripts can still be opened via idle. and executable when it is opened and F5 pressed.
if on windows or linux, right click, open with ... select python executable, or Idle. whichever you want the default action to be.
then select the option to "always use this to open .py files"
If on a Mac, you can CTRL+Click the file, Get info > Open With and change it to Python Launcher. Click Change All. Double clicking should run the script.
Another way is to use pyinstaller which makes the script into an executable. It is pretty straightforward to use.
Change the "open with..." preference for the py files by shift + right click and choose open with from the menu. Make sure you tick the use always option

How to open PYW files in Windows 8

Someone gave me a python file to open and use as a resource. The only issue is I don't know anything about python, it's very different from my basic knowledge of coding.
The file is not a normal .py file, but rather a console-less .pyw file. I have imported the newest version of python and installed PySide, but I have had no successful attempts at opening the file.
I was wondering if someone might know how to open this kind of file? Does it need to be somewhere specific?
Right-click the file, click properties, under general it says "opens with:"...
Click the "Change" button to the right of that, and then click more options. On that menu there should be an option called "pythonw" click that. Then on the bottom-right click "apply", then "OK". Then just double-click on the file and it should run with no console window so you won't be able to see it running.

Open and Control an Application with Python

I'm using Python and I want to open Notepad++ with a specific .xml file. I am able to do that with the following code:
os.system('start notepad++.exe m1.xml')
What I want to do after this is use a plug in on Notepad called 'pretty print xml' that's under the plug-ins menu, but I have no idea how to access it with just code. I was wondering if anyone knows a way to access this item without installing plug ins for Python; I don't want to have to install a plug in for Python, I want to be able to use Python to control the Notepad++ application.
Basically, via code, I want to:
Open the document [done]
Open a menu in notepad
Click a specific button in that menu
Save the document

py2exe - Can no longer Copy/Paste text from other Windows app to my Python app after converting my python script to a .EXE file

I recently tried to convert one of my python scripts (used for file-systems I/O) to a executable file by using py2exe. However, after successfully generating the .exe file from my python script, I am no longer able to copy and paste any text(or anything for that matter) from other windows apps to my python app console (when I run the script/app from the .exe file). When right click the mouse now, the access window does not pop up any longer. Does anyone know how I can get around this issue?
Thanks,
A.L.
Right-clicking a console window is a "special feature" of the command line interpreter of Windows Vista and above. It doesn't work on any other command-line tool, so it doesn't longer works for your converted script. You can still access it using the windows menu (small icon in the title bar or Alt+Space).
You could try to get the right-click feature back by messing around with Windows API calls - but the more convenient possibility would be to enable pasting using Ctrl+V and forget about the window menu. A good candidate is PyReadline - install the package and run this at the beginning of your script:
import readline
readline.parse_and_bind("control-v: paste")

how to control the buttons or tabs in the launch application using python

i launched the application using the following code i.e.
import os
cmd = r'start C:\WindowsMediaPlayer\wmplayer.exe'
os.system(cmd)
say i launched win media player.. now i want to control the buttons/the menus to open a file . or do some audio settings.. any thing that is related to media player using the python script.. please any on can help me with this....
Maybe you should use a framework such as pywinauto
Using this, you can launch windows applications and control them.
Check this out

Categories

Resources