我在 OSX 上使用 Python 2.x、Selenium 和 Firefox
我正在使用 Python 和 Selenium 自动测试 JavaScript Web 应用程序。
应用程序中的一个链接(添加文件)会打开一个名为“文件上传”的非浏览器 Firefox 窗口,它看起来像(/是?)一个 Finder 窗口。
有没有办法可以从我的 python 脚本中找到并控制这个窗口?我知道 Selenium 无法做到这一点,但我想知道是否可以使用“import applescript”之类的东西来实现,如果可以的话如何实现?
最佳答案
我找到了atomac它允许我通过其辅助功能控件来控制 Mac 应用程序(需要在 Mavericks for Aptana 上的系统偏好设置 -> 安全和隐私 -> 隐私 -> 可访问性中启用)。很酷的工具,但文档非常稀疏。上面页面上提供的示例让我可以通过取消按钮关闭窗口,但我必须查看atomac的 AXClasses.py 中的函数定义才能弄清楚其余部分。这是解决方案。
import atomac, time
from atomac.AXKeyCodeConstants import *
# to allow me to make firefox frontmost while testing
time.sleep(5)
# get a reference to the running app
firefox = atomac.getAppRefByLocalizedName('Firefox')
# get the window of the reference
firefoxwindow = firefox.windowsR()[0]
# send key sequence to go to my home folder
firefoxwindow.sendKeyWithModifiers('h',[COMMAND,SHIFT])
# send key sequence to select first file there
firefoxwindow.sendKeyWithModifiers('a',[COMMAND])
# press the now active Open button
openbutton = firefoxwindow.buttons('Open')[0]
openbutton.Press()
关于python - 如何控制属于 Firefox 的非浏览器窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096434/