python - 如何控制属于 Firefox 的非浏览器窗口?

标签 python selenium selenium-webdriver applescript

我在 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/

相关文章:

python - 使用 PyMySQL 向 MySQL 中的表中插入数据

python - 使用 python/django 关闭套接字并避免 Errno 10054 的正确方法是什么

ruby-on-rails - Rails 和 Selenium : how to stop/pause execution of a test in the browser?

selenium - 将 Selenium ChromeDriver UserPreferences 设置为另存为 PDF

python - 使用 numpy 的数组广播转换简单的 for 循环

python - Heroku Django 应用程序未加载静态文件(404 未找到)

python - 计算多对多关系中的行数 (SQLAlchemy)

python - 如何单击动态加载的链接?

javascript - Protractor 切换到上一个选项卡

java - 如何点击页面刷新时 id 不断变化的日期选择器