Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何控制作为Firefox一部分的非浏览器窗口?_Python_Selenium_Selenium Webdriver_Applescript - Fatal编程技术网

Python 如何控制作为Firefox一部分的非浏览器窗口?

Python 如何控制作为Firefox一部分的非浏览器窗口?,python,selenium,selenium-webdriver,applescript,Python,Selenium,Selenium Webdriver,Applescript,我在OSX上使用Python2.x、Selenium和Firefox 我正在用Python和Selenium自动化测试javascript Web应用程序 应用程序中的一个链接(添加文件)打开一个名为“文件上传”的非浏览器firefox窗口,它看起来像一个查找窗口 有没有一种方法可以从python脚本中找到并控制此窗口?我知道Selenium无法做到这一点,但我想知道像“import applescript”这样的东西是否可能实现,如果可能,如何实现?理论上是可能的,但真的很尴尬。我会给你一些链

我在OSX上使用Python2.x、Selenium和Firefox

我正在用Python和Selenium自动化测试javascript Web应用程序

应用程序中的一个链接(添加文件)打开一个名为“文件上传”的非浏览器firefox窗口,它看起来像一个查找窗口


有没有一种方法可以从python脚本中找到并控制此窗口?我知道Selenium无法做到这一点,但我想知道像“import applescript”这样的东西是否可能实现,如果可能,如何实现?

理论上是可能的,但真的很尴尬。我会给你一些链接——我知道这并不理想,但你可以写一本关于这个的书


你需要从这开始。然后,您需要从Applescript中阅读。但是,您希望使用Python而不是AppleScript,因此需要安装,这是一个Python到Cocoa的桥。您需要使用脚本桥框架,并从中找出如何将AppleScript文档转换为Python。

这在理论上是可能的,但实际上很尴尬。我会给你一些链接——我知道这并不理想,但你可以写一本关于这个的书

你需要从这开始。然后,您需要从Applescript中阅读。但是,您希望使用Python而不是AppleScript,因此需要安装,这是一个Python到Cocoa的桥。您需要使用脚本桥框架并(从中)找出如何将AppleScript文档转换为Python。

我找到了一种方法,可以通过mac应用程序的可访问性控件来控制mac应用程序(需要在Mavericks for Aptana的系统首选项->安全和隐私->可访问性中启用)。很酷的工具,但是文档非常稀少。上面页面上提供的示例使我能够通过cancel按钮关闭窗口,但我必须查看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()
我发现它允许我通过可访问性控制来控制mac应用程序(需要在Mavericks for Aptana的系统首选项->安全和隐私->隐私->可访问性中启用)。很酷的工具,但是文档非常稀少。上面页面上提供的示例使我能够通过cancel按钮关闭窗口,但我必须查看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()

谢谢通过查看这些内容以及与脚本桥相关的内容,我找到了atomac及其解决方案。谢谢你给我指出了正确的方向。谢谢!通过查看这些内容以及与脚本桥相关的内容,我找到了atomac及其解决方案。谢谢你给我指明了正确的方向。