Find Elements issue on the pywinauto - python

I recently tried to automate a windows application using a pywinauto since it enables automation with using python. I just started it and encountered a problem which hinders me to continue.
I get this error whenever I try to find the relevant element:
Traceback (most recent call last):
File "test.py", line 14, in <module>
app.findwindows.find_elements().click_input()
File "C:\Users\Bar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywinauto\application.py", line 173, in __call__
format(self.criteria[-1]['best_match']))
AttributeError: WindowSpecification class has no 'find_elements' method
This is my code:
from pywinauto.application import Application
import pywinauto
import time
app = Application(backend='uia').start(r"C:\Program
Files\Intellech\Analyzer\Suite.exe")
time.sleep(3)
app.findwindows.find_windows(auto_id='btQuick').click_input()
Can you help me to find out the reason of this error?

findwindows is a module name, not an attribute of Application object. This is correct code for the last line:
app.window(title="Your Main Window").child_window(auto_id='btQuick').click_input()
where "Your Main Window" should be changed to correct text of the top level window.

Related

launch URL in Flet

I'm using Flet and I want for my app to launch a link when clicking on a button.
According to the docs, I can use launch_url method. But when I tried, I got the following error:
Exception in thread Thread-6 (open_repo):
Traceback (most recent call last):
File "C:\Users\Iqmal\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
self.run()
File "C:\Users\Iqmal\AppData\Local\Programs\Python\Python311\Lib\threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "d:\Iqmal\Documents\Python Projects\flet-hello\main.py", line 58, in open_repo
ft.page.launch_url('https://github.com/iqfareez/flet-hello')
^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute 'launch_url'
Code
import flet as ft
def main(page: ft.Page):
page.padding = ft.Padding(20, 35, 20, 20)
page.theme_mode = ft.ThemeMode.LIGHT
appbar = ft.AppBar(
title=ft.Text(value="Flutter using Flet"),
bgcolor=ft.colors.BLUE,
color=ft.colors.WHITE,
actions=[ft.IconButton(icon=ft.icons.CODE, on_click=open_repo)])
page.controls.append(appbar)
page.update()
def open_repo(e):
ft.page.launch_url('https://github.com/iqfareez/flet-hello')
ft.app(target=main, assets_dir='assets')
I 'solved' this issue by moving the open_repo() function inside the main() function block. Now, the link can be opened on a browser when clicked. Example:
def main(page: ft.Page):
def open_repo(e):
page.launch_url('https://github.com/iqfareez/flet-hello')
appbar = ft.AppBar(
title=ft.Text(value="Flutter using Flet"),
bgcolor=ft.colors.BLUE,
color=ft.colors.WHITE,
actions=[ft.IconButton(icon=ft.icons.CODE, on_click=open_repo)])
# code truncated for clarity
Full code here.
From what I'm seeing here and the errors you're getting it's just possible you might have a problem with the installation of Flet. Try installing running in a virtual environment and see if it changes.
Good Luck

Python Tkinter --AttributeError

Cannot seem to figure out the below Tkinter message. Usually doing a quick
search will provide answers but this time I seem to miffed the search engines as to
what might be causing the below error. Curious to know if I am missing a Python package or line 25 below is used in an older version of Python and it has been updated to
a newer command.
I am importing the following packages into the script:
from tkinter import *
from tkinter import filedialog
The function is suppose to save any typed text put into a text area. It does save the file but the file is empty.
Thanks,
Kurt
C:\Users\kurt>python --version
Python 3.10.4
def saveFiles():
filename = filedialog.asksaveasfile(
mode='w',
title="Save a File",
defaultextension=".txt"
)
filename.config(mode='w') ------------> **This is line 25**
pathh.insert(END, filename)
data = str(txtarea.get(1.0, END))
filename.write(data)
filename.close()
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1264.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\kurt\Documents\Scripts\TKinter\fileExplorerReadFile.py", line 25, in saveFiles
filename.config(mode='w')
AttributeError: '_io.TextIOWrapper' object has no attribute 'config'
The error is saying that the object returned by the asksaveasfile method doesn't have a config method.
tkinter.filedialog.asksaveasfile(mode='w', **options)ΒΆ
Create a SaveAs dialog and return a file object opened in write-only mode.
When you call the asksaveasfile method, it automatically returns a file object in write mode already so there is no need for any further configuration to write to the file. If you were to omit the line throwing the error, your code should work the way you intended.

AttributeError module 'select' has no attribute 'poll'

May I ask for some help? I am attempting to clone an existing GitHub project and am struggling to identify what I could be doing wrong. The project is a pluggable SXM music player written in Python ( https://github.com/AngellusMortis/sxm-player), that I've cloned and attempted to run through Visual Studio Code (v1.65.2). Upon executing the project, the code returns an error - "Exception has occurred: AttributeError module 'select' has no attribute 'poll'". Little doubt that I must be doing something incorrectly - but to this point, I haven't been able to identify what I need to do differently to get it to run properly. My sincerest apologies for needing to ask this probably simple question on this forum, but I know that this would be the place to find the experience to get this package up and running and any assistance would be greatly appreciated.
Here is the traceback for the error message:
File "C:\GitHub\sxm-player\sxm_player\utils.py", line 173, in FFmpeg
_stderr_poll: Optional[select.poll] = None
File "C:\GitHub\sxm-player\sxm_player\utils.py", line 169, in <module>
class FFmpeg:
File "C:\GitHub\sxm-player\sxm_player\runner.py", line 9, in <module>
from sxm_player.utils import configure_root_logger
File "C:\GitHub\sxm-player\sxm_player\handlers.py", line 6, in <module>
from sxm_player.runner import Runner, Worker
File "C:\GitHub\sxm-player\sxm_player\cli.py", line 23, in <module>
from sxm_player import handlers
File "C:\GitHub\sxm-player\sxm_player\__main__.py", line 3, in <module>
from sxm_player.cli import main

python error importing pyttsx

I have been trying to make a basic speech recognition system in python, using pyttx, however, when i run my code:
import speech_recognition
import pyttsx
I get this error:
Traceback (most recent call last):
File "C:\Users\brett\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyttsx__init__.py", line 37, in init
eng = _activeEngines[driverName]
File "C:\Users\brett\AppData\Local\Programs\Python\Python36-32\lib\weakref.py", line 131, in getitem
o = self.datakey
KeyError: 'sapi5'
I have tried all solutions on here so far and none of them work, if i try to run the engine driver in pyttsx, I get an error with the driver.py, saying 'main' is not a pack. if i have left out any other info, just let me know

not able to create a web driver instance in python

I am trying to create a web driver instance in the python with the following code:
from robot.libraries.BuiltIn import BuiltIn
import Selenium2Library
from Selenium2Library import Selenium2Library
def get_webdriver_instance():
s2l = BuiltIn().get_library_instance("Selenium2Library")
return s2l._current_browser()
but at BuiltIn().get_library_instance("Selenium2Library") I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 2922, in get_library_instance
return self._namespace.get_library_instance(name)
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 70, in _namespace
return self._context.namespace
File "/usr/lib/python2.6/site-packages/robot/libraries/BuiltIn.py", line 65, in _context
raise RobotNotRunningError('Cannot access execution context')
robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context
Could someone please help me in resolving this error
The error message is telling you that you can't use methods of the BuiltIn library unless you are actually running a test (via pybot, jybot, etc). You can't call BuiltIn().get_library_instance('Selenium2Library') in a standalone python script.
_current_browser is only return the current browser
If you want to use Selenium2Library in python than you can do the next
from Selenium2Library import Selenium2Library
sl = Selenium2Library()
sl.open_browser('firefox')

Categories