python - 如何使用 python、selenium 在 Mac 上设置焦点?
问题描述
if platform == "darwin": #if on OS X, requires this module: pip install pygetwindow
import pygetwindow as gw
titles = gw.getAllTitles()
print(titles)
win = gw.getWindowsWithTitle('Photoshop')
win.activate()
这是终端中的结果:
['SystemUIServer ', 'Control Centre ', 'Control Centre ', 'Spotlight ', 'Control Centre ', 'SystemUIServer ', 'Control Centre ', 'Window Server Menubar', 'Dock ', 'Photoshop ', 'Terminal ', 'IDLE ', 'Finder ', 'Finder ']
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1892, in __call__
return self.func(*args)
File "/Users/username/Library/Mobile Documents/com~apple~CloudDocs/test.py", line 1237, in clicker1
week_or_month()
File "/Users/username/Library/Mobile Documents/com~apple~CloudDocs/test.py", line 899, in week_or_month
window_focus()
File "/Users/username/Library/Mobile Documents/com~apple~CloudDocs/test.py", line 680, in window_focus
win = gw.getWindowsWithTitle('Photoshop')
AttributeError: module 'pygetwindow' has no attribute 'getWindowsWithTitle'
有没有办法解决这个问题并专注于窗口“Photoshop”?函数 gw.getAllTitles() 有效。
我也试过这个(如另一篇文章中所述),结果相同:
win = pyautogui.getWindowsWithTitle("Photoshop")
结果:
AttributeError: module 'pyautogui' has no attribute 'getWindowsWithTitle'
解决方案
这是因为您使用了错误的调用,请尝试查看文档中的文档或按照我的示例进行操作。
你的错误:
AttributeError: module 'pygetwindow' has no attribute 'getWindowsWithTitle'
尝试
pygetwindow.getWindowsWithTitle('Photoshop') # I dont understand why you need to index into a "list"
另外,如果这不起作用,请尝试该gw.getAllTitles()
方法。 ('', 'C:\\WINDOWS\\system32\\cmd.exe - pipenv shell - python'")
代替(Win32Window(hWnd=131318), Win32Window(hWnd=1050492), Win32Window(hWnd=67206))
推荐阅读
- docker - Docker 映像构建无法识别构建参数:无效的参考格式
- r - Tidyeval:如何在没有用户引用的情况下将带有引用元素的列表传递给嵌套函数?
- excel - 如何获得每日和每小时平均值?
- php - 将 PHP 设置为全局使用 HTTP 1.1 请求
- python - 我无法按索引类型从列表中删除项目
- python - 使用 python 格式化字符串
- c++ - QTimer::singleShot(..) 在 connect(..) 函数中
- azure-devops - 当史诗般的关闭日期是电子邮件通知
和目标日期 < 今天的日期? - python - Python ursina:通过改变 FOV 的值来瞄准(动画问题)
- pyspark - 如何对数据框的每一行进行排序?