Python Pywinauto Internet Explorer

Python Pywinauto Internet Explorer,python,pywinauto,Python,Pywinauto,我正在尝试用pywinauto控制Internet Explorer。Windows 8,IE v11我正在使用how tos中的一个示例,我得到了一个 ElementNotFoundError{'process':7616,'title_re':'。Windows Internet 资源管理器“,”后端“:u'win32'} 有人知道怎么解决这个问题吗?似乎必须使用另一个函数,但到目前为止,我无法在“帮助”部分找到它 这一行是问题所在,尽管我在做帮助部分所说的 ie = app.window

我正在尝试用pywinauto控制Internet Explorer。Windows 8,IE v11我正在使用how tos中的一个示例,我得到了一个

ElementNotFoundError{'process':7616,'title_re':'。Windows Internet 资源管理器“,”后端“:u'win32'}

有人知道怎么解决这个问题吗?似乎必须使用另一个函数,但到目前为止,我无法在“帮助”部分找到它

这一行是问题所在,尽管我在做帮助部分所说的

ie =  app.window(title_re = ".*Windows Internet Explorer.*")

# GUI Application automation and testing library
# Copyright (C) 2006-2017 Mark Mc Mahon and Contributors
# https://github.com/pywinauto/pywinauto/graphs/contributors
# http://pywinauto.readthedocs.io/en/latest/credits.html
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
#
# * Neither the name of pywinauto nor the names of its
#   contributors may be used to endorse or promote products derived from
#   this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function

try:
    from pywinauto import application
except ImportError:
    import os.path
    pywinauto_path = os.path.abspath(__file__)
    pywinauto_path = os.path.split(os.path.split(pywinauto_path)[0])[0]
    import sys
    sys.path.append(pywinauto_path)
    from pywinauto import application

import sys
import time
import os.path

if len(sys.argv) < 2:
    print("please specify a web address to download")
    sys.exit()

web_address = sys.argv[1]

if len(sys.argv) > 2:
    outputfilename = sys.argv[2]
else:
    outputfilename = web_address
    outputfilename = outputfilename.replace('/', '')
    outputfilename = outputfilename.replace('\\', '')
    outputfilename = outputfilename.replace(':', '')

outputfilename = os.path.abspath(outputfilename)


# start IE with a start URL of what was passed in
app = application.Application().start(
    r"c:\program files\internet explorer\iexplore.exe {}".format(web_address))

# some pages are slow to open - so wait some seconds
time.sleep(10)

ie =  app.window(title_re = ".*Windows Internet Explorer.*")

# ie doesn't define it's menus as Menu's but actually as a toolbar!
print("No Menu's in IE:", ie.menu_items())
print("They are implemented as a toolbar:", ie.Toolbar3.texts())

ie.type_keys("%FA")
#ie.Toolbar3.press_button("File")
app.SaveWebPage.Edit.set_edit_text(os.path.join(r"c:\.temp", outputfilename))


app.SaveWebPage.Save.close_click()

# if asked to overwrite say yes
if app.SaveWebPage.Yes.Exists():
    app.SaveWebPage.Yes.close_click()

print("saved:", outputfilename)

# quit IE
ie.type_keys("%FC")
ie=app.window(title\u re=“.*Windows Internet Explorer.*”)
#GUI应用程序自动化和测试库
#版权所有(C)2006-2017 Mark Mc Mahon和贡献者
# https://github.com/pywinauto/pywinauto/graphs/contributors
# http://pywinauto.readthedocs.io/en/latest/credits.html
#版权所有。
#
#以源代码和二进制形式重新分发和使用,带或不带
#如果满足以下条件,则允许进行修改:
#
#*源代码的重新分发必须保留上述版权声明,本
#条件列表和以下免责声明。
#
#*二进制形式的重新分发必须复制上述版权声明,
#此条件列表和文档中的以下免责声明
#和/或分发时提供的其他材料。
#
#*既不是pywinauto的名称,也不是其
#投稿人可能被用来支持或推广源于
#本软件未经事先书面许可。
#
#本软件由版权所有者和贡献者“按原样”提供
#以及任何明示或暗示的保证,包括但不限于
#对适销性和特定用途适用性的默示保证如下:
#否认。在任何情况下,版权持有人或贡献者均不承担任何责任
#对于任何直接、间接、附带、特殊、示范或后果
#损害赔偿(包括但不限于采购替代货物或
#服务;使用、数据或利润损失;或业务中断)
#根据任何责任理论,无论是在合同中,还是在严格责任中,
#或因使用而产生的侵权行为(包括疏忽或其他)
#即使被告知有可能发生此类损坏,也不得使用本软件。
来自未来导入打印功能
尝试:
从pywinauto导入应用程序
除恐怖外:
导入操作系统路径
pywinauto_path=os.path.abspath(_文件)
pywinauto_path=os.path.split(os.path.split(pywinauto_path)[0])[0]
导入系统
sys.path.append(pywinauto_路径)
从pywinauto导入应用程序
导入系统
导入时间
导入操作系统路径
如果len(系统argv)<2:
打印(“请指定要下载的网址”)
sys.exit()
web_address=sys.argv[1]
如果len(sys.argv)>2:
outputfilename=sys.argv[2]
其他:
outputfilename=web\u地址
outputfilename=outputfilename.replace('/','')
outputfilename=outputfilename.replace('\\','')
outputfilename=outputfilename.replace(':','')
outputfilename=os.path.abspath(outputfilename)
#使用传入内容的起始URL启动IE
app=application.application().start(
r“c:\ProgramFiles\internet explorer\iexplore.exe{}”.format(网址))
#有些页面打开很慢-请等待几秒钟
时间。睡眠(10)
ie=app.window(title_re=“.*Windows Internet Explorer.*”)
#ie没有将它的菜单定义为菜单,而是将它定义为工具栏!
打印(“IE:,IE.菜单项()中没有菜单”)
打印(“它们被实现为工具栏:”,即Toolbar3.text()
ie.type_键(“%FA”)
#ie.3.按下按钮(“文件”)
app.SaveWebPage.Edit.set\u Edit\u文本(os.path.join(r“c:\.temp”,outputfilename))
app.SaveWebPage.Save.close_click()
#如果要求覆盖,请回答是
如果app.SaveWebPage.Yes.Exists():
app.SaveWebPage.Yes.close_click()
打印(“已保存:”,输出文件名)
#戒烟
ie.type_键(“%FC”)

Windows版本?IE版本?Windows 8,IE v11OK,我看到脚本是为旧的IE版本编写的。我们可能需要使用
backend='uia'
刷新它。最近两周我很忙我的学生,主要工作等。如果你已经阅读了(主要概念和其他有用的东西),你可以试着自己重新写这个例子。我们始终欢迎拉取请求!;)