Error during automated software install using pywinauto - python

After searching I am not able to find a good response:
I am trying to automate company software using pywinauto. I try to use app.print_control_identifiers() wherever possible. And it has been a God send! Thanks to folks on Youtube and Vasily's posts. See code below.
During the install, it wants to install a MS VC++ redistributable and I can handle that.
The next issue is telling me that the version of Adobe Flash Player (I know right?) is incompatible. I have used Inspect to ID the OK button I need to click to move on. Here is the code (cleaned up for public consumption):
from pywinauto.application import Application
import time
app = Application(backend="uia").start("C:\\Users\\me\\program.exe")
time.sleep(5)
#This addresses the need to install Microsoft C++ Redistributable
dlg = app['program - InstallShield Wizard']
dlg.Install.click()
time.sleep(5)
#This is to get past an install failure and to move on
dlg.Yes.click()
time.sleep(10)
#This is a dialog box saying that some component is incompatible and this is where I am stuck
# And the window title now just says 'program' vs. 'program - InstallShield Wizard'
new_dlg = app['program']
new_dlg.OK.click()
Here is the failure info:
C:\Python37\python.exe C:/Users/me/PycharmProjects/myProject/pywinauto_install.py
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 258, in __resolve_control
criteria)
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/me/PycharmProjects/myProject/pywinauto_install.py", line 23, in <module>
new_dlg.OK.click()
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 203, in __get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'best_match': 'program', 'backend': 'uia', 'process': 22184}
Process finished with exit code 1
I am creating new_dlg based on an SO post I saw, so if this is wrong, please slap my hand. I am not a trained developer.
Thanks

To check texts of the top level dialog windows print this:
print([w.window_text() for w in app.windows()])
Then just copy the correct one to your code as a dict key instead of app['program']. More flexible way looks so:
new_dlg = app.window(title_re="Program - .*")

Related

djangosaml2idp problems with launch: saml2.sigver.MissingKey: http://localhost:8000/saml2/metadata/

I'v been trying to launch project(example_setup folder):
https://github.com/OTA-Insight/djangosaml2idp/tree/master/example_setup
I can anybody answer to men according with documentation. But it does not working. First problem, as I undesrtand is in date of methadata in SP(idp_metadata.xml)- validUntil="2020-12-27T12:41:18Z"> . It does not valid at the moment, and was changed to future date, as example(validUntil="2030-12-27T12:41:18Z"). But next I got another problem when trying to sign in to SP(localhost:8000) in my browser, I have more problem:
Error during SAML2 authentication
IncorrectlySigned
In attempts to find problem, I found the place where it is occured. In original it iis in tryexcept block, and can't be found easy.
Traceback (most recent call last):
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/djangosaml2idp/views.py", line 251, in get
req_info = idp_server.parse_authn_request(request.session['SAMLRequest'], binding)
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/server.py", line 238, in parse_authn_request
return self._parse_request(enc_request, AuthnRequest,
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/entity.py", line 1036, in _parse_request
_request = _request.loads(xmlstr, binding, origdoc=enc_request,
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/request.py", line 110, in loads
return self._loads(xmldata, binding, origdoc, must,
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/request.py", line 51, in _loads
print(self.signature_check(xmldata, origdoc=origdoc,
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/sigver.py", line 1662, in correctly_signed_authn_request
return self.correctly_signed_message(decoded_xml, 'authn_request', must, origdoc, only_valid_cert=only_valid_cert)
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/sigver.py", line 1653, in correctly_signed_message
return self._check_signature(
File "/home/dmitriy/projects/djangosaml2idp/example_setup/idp/venv/lib/python3.8/site-packages/saml2/sigver.py", line 1503, in _check_signature
raise MissingKey(_issuer)
saml2.sigver.MissingKey: http://localhost:8000/saml2/metadata/
Internal Server Error: /idp/login/process/
Some key is missing:
Error during SAML2 authentication
MissingKey
http://localhost:8000/saml2/metadata/
My idp_metada in the SP is like in the [example_setup][1] folder of project, only validUntil has been changed as I said above, user in IDP has been created as superuser, I also tried to create user in the SP, the same as in the IDP, but nothing changed
Can anybody anser to me, what my problem is?
It's no any information in docs. But you need to create SP inside IDP from admin panel. That was resolved my problem.

Unable to build V8 in Windows 10

I'm using this link as reference (https://medium.com/angular-in-depth/how-to-build-v8-on-windows-and-not-go-mad-6347c69aacd4) to build v8 but i think its out of date or i'm doing something wrong.
I can't run this (ninja -C out.gn/x64.release) command because its showing this error constantly
ninja: error: loading 'build.ninja': The system cannot find the file specified.
ninja: Entering directory `out.gn\foo
also im getting this error too
D:\v8_dev\v8Engine\v8>gn args out.gn\foo
Waiting for editor on "D:\v8_dev\v8Engine\v8\out.gn\foo\args.gn"...
Generating files...
Traceback (most recent call last):
File "D:/v8_dev/v8Engine/v8/build/vs_toolchain.py", line 561, in <module>
sys.exit(main())
File "D:/v8_dev/v8Engine/v8/build/vs_toolchain.py", line 557, in main
return commands[sys.argv[1]](*sys.argv[2:])
File "D:/v8_dev/v8Engine/v8/build/vs_toolchain.py", line 371, in CopyDlls
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
File "D:/v8_dev/v8Engine/v8/build/vs_toolchain.py", line 346, in _CopyRuntime
suffix)
File "D:/v8_dev/v8Engine/v8/build/vs_toolchain.py", line 284, in _CopyUCRTRuntime
assert len(ucrt_files) > 0
AssertionError
ERROR at //build/toolchain/win/BUILD.gn:49:3: Script returned non-zero exit code.
exec_script("../../vs_toolchain.py",
^----------
Current dir: D:/v8_dev/v8Engine/v8/out.gn/foo/
Command: D:/v8_dev/depot_tools/bootstrap-3_8_0_chromium_8_bin/python/bin/python.exe D:/v8_dev/v8Engine/v8/build/vs_toolchain.py copy_dlls D:/v8_dev/v8Engine/v8/out.gn/foo Release x64
Returned 1.
See //BUILD.gn:905:1: which caused the file to be included.
action("postmortem-metadata") {
^------------------------------
Ultimately i want it to work like as its shown in the embedded picture
if you are looking for the solution then follow this link (https://github.com/pmed/v8-nuget) for visual studio users, its working really well without all the hassle.

How to use pywinauto to set_text in python IDLE editor?

I want to control python IDLE with pywinauto.
I can start IDLE but cannot input text.
Here is my code:
import pywinauto
app = pywinauto.application.Application(backend="uia").start(r"C:\Python37\pythonw.exe C:\Python37\Lib\idlelib\idle.pyw")
app2 = pywinauto.application.Application().connect(process=app.process)
I tried to use app2.Property.print_control_identifiers() but it returns:
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 256, in __resolve_control
criteria)
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
app2.Property.print_control_identifiers()
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 595, in print_control_identifiers
this_ctrl = self.__resolve_control(self.criteria)[-1]
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 259, in __resolve_control
raise e.original_exception
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 201, in __get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
elements = find_elements(**kwargs)
File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 303, in find_elements
elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems)
File "C:\Python37\lib\site-packages\pywinauto\findbestmatch.py", line 533, in find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'Property' in 'dict_keys(['*Python 3.7.2 Shell*TkTopLevel', '*Python 3.7.2 Shell*', 'TkTopLevel'])'
How to solve the problem?
Thank you.
app = pywinauto.application.Application(backend="uia").start(r"C:\Python37\pythonw.exe C:\Python37\Lib\idlelib\idle.pyw")
app2 = pywinauto.application.Application().connect(process=app.process)
app3 = app2.top_window()
app3.print_control_identifiers()
I doubt that you can do whatever it is that you are trying to do. The pywinauto site says "pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls." IDLE uses tkinter, which uses the tcl/tk gui framework. While that ultimately uses Windows graphics, it may not be at the level that pywinauto accesses.
You can use pyautogui which is best for windows GUI automation
I converted RDP connection to automation using pyautogui
import pyautogui
import time
import os
os.system("C:\\Users\Administrator\\Desktop\\RDC.bat")
print(pyautogui.position())
time.sleep(5)
pyautogui.click(490,404)
pyautogui.typewrite("Bitwise$123")
pyautogui.typewrite(["Enter"])

Using language check module for python - "can't find Java" error

I'm planning to use the Language-check module for python 3 in my poem making code. I was just testing it with
import language_tool
lang_tool = language_tool.LanguageTool("en-US")
text = "A sentence with a error in the Hitchhiker’s Guide tot he Galaxy"
matches = lang_tool.check(text)
print(len(matches))
but it gave me this error.
Traceback (most recent call last):
File "/home/runner/.site-packages/language_tool/__init__.py", line 548, in get_server_cmd
cmd = cache["server_cmd"]
KeyError: 'server_cmd'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/runner/.site-packages/language_tool/__init__.py", line 559, in get_jar_info
java_path, jar_path = cache["jar_info"]
KeyError: 'jar_info'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 10, in <module>
lang_tool = language_tool.LanguageTool("en-US")
File "/home/runner/.site-packages/language_tool/__init__.py", line 188, in __init__
self._start_server_on_free_port()
File "/home/runner/.site-packages/language_tool/__init__.py", line 323, in _start_server_on_free_port
cls._start_server()
File "/home/runner/.site-packages/language_tool/__init__.py", line 335, in _start_server
server_cmd = get_server_cmd(cls._port)
File "/home/runner/.site-packages/language_tool/__init__.py", line 550, in get_server_cmd
java_path, jar_path = get_jar_info()
File "/home/runner/.site-packages/language_tool/__init__.py", line 563, in get_jar_info
raise JavaError("can’t find Java")
language_tool.JavaError: can’t find Java
I've looked at some similar questions and I know I probably need to put something in 'Path' but I don't know what specifically to enter. Thanks for your help!
Also I'm on doing this on repl.it, not IDLE.
Note: I'm adding this as an actual answer because the question was resolved in the comments.
Your question says:
Also I'm on doing this on repl.it, not IDLE.
That means that you need to install this module and all its prerequisites into your repl.it environment, not into your local machine.
On the BitBucket link you provided, under "Prerequisites", the page says:
LanguageTool requires Java 6 or later.
So you will need to ensure Java is installed into your repl.it environment somehow. I don't know whether that is possible or not. Alternatively, you can simply install this package and all its prerequisites locally instead.

How to run python programs in pycharm with passing parameters?

I am currently having problem running python programs in pycharm, I generally used to right click and run the program. I want to run the program like this:
python hrllo.py rahulkapoo vit university
Here is the error I get:
Traceback (most recent call last):
File "C:/Users/rahul/PycharmProjects/untitled/hrllo.py", line 107, in <module>
aggregate()
File "C:/Users/rahul/PycharmProjects/untitled/hrllo.py", line 88, in aggregate
br = login()
File "C:/Users/rahul/PycharmProjects/untitled/hrllo.py", line 23, in login
response = br.open('https://academics.vit.ac.in/student/stud_login.asp')
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 255, in _mech_open
raise response
mechanize._response.httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt
Process finished with exit code 1
In PyCharm, right-click on the script (or within the editor window that has the script open, click Create 'scriptname', put your params in the Script Parameters box near the top and click OK.
The new run config will appear to the left of the run button at the top of Pycharm (at least in my version it does). Now make sure that the new run config is listed when running the script.

Categories