我正在使用pywinauto自动化个人项目的第三方应用程序。 面对一个奇怪的问题,pywinauto返回True为dialog.Exist但对话框实际上不可见。因此,由于代码返回True,对对话框的进一步操作将失败。我相信应用程序缓存了对话框或其他内容。不知道如何处理这个。
from itertools import chain, count
import json
import networkx as nx
from networkx.utils import make_str
__author__ = """Aric Hagberg <hagberg@lanl.gov>"""
_attrs = dict(id='id', source='source', target='target', key='key')
def node_link_data(G, attrs=_attrs):
"""Return data in node-link format that is suitable for JSON serialization
and use in Javascript documents.
"""
multigraph = G.is_multigraph()
id_ = attrs['id']
source = attrs['source']
target = attrs['target']
# Allow 'key' to be omitted from attrs if the graph is not a multigraph.
key = None if not multigraph else attrs['key']
if len(set([source, target, key])) < 3:
raise nx.NetworkXError('Attribute names are not unique.')
mapping = dict(zip(G, count()))
data = {}
data['nodes'] = [dict(chain(G.node[n].items(), [(id_, n)])) for n in G]
if multigraph:
data['links'] = [
dict(chain(d.items(),
[(source, u), (target,v), (key, k)]))
for u, v, k, d in G.edges_iter(keys=True, data=True)]
else:
data['links'] = [
dict(chain(d.items(),
[(source, u), (target, v)]))
for u, v, d in G.edges_iter(data=True)]
return data
这是输出
app = Application().connect(path = "D:/myapp/Trader.exe")
existFlag = app.window_(title ="Trader - 23506").Exists(timeout =2)
print existFlag #Returns True
if(existFlag):
app.window_(title ="Trader - 23506").Close() #Fails
答案 0 :(得分:1)
是的,Win32应用程序可以拥有不可见的现有窗口。要查看可见性,您可以将其称为:
visible = app.window(title ="Trader - 23506").is_visible()
或者它可能是一个时间问题(如果在约50%的情况下失败或现有窗口在.exists(...)
调用后立即消失)。因此,处理关闭对话框的另一种方法是:
dlg = app.window_(title ="Trader - 23506")
try:
dlg.wait_not('visible', timeout=2)
except Exception: # or timings.TimeoutError
dlg.close()