【发布时间】:2017-08-01 20:25:24
【问题描述】:
这个测试脚本正是复制我的问题的场景。
import atomac, time
noront = atomac.getAppRefByBundleId(BUNDLE_ID)
noront.activate()
time.sleep(5)
ax = {'AXRole' : 'AXButton'}
toggle = noront.findAllR(**ax)
print "Toggle is ", toggle
with open("/tmp/test1.txt", 'w') as fp:
fp.write(str(toggle))
当我在终端中运行这个脚本时,我得到了输出
python /Users/user/Desktop/test.py
当我跑步后 猫 /tmp/test1.txt
[<atomac.AXClasses.NativeUIElement AXButton u'I agree'>, <atomac.AXClasses.NativeUIElement AXButton u'I Accept'>, <atomac.AXClasses.NativeUIElement AXButton u'Pr P'>, <atomac.AXClasses.NativeUIElement AXButton None>, <atomac.AXClasses.NativeUIElement AXButton None>, <atomac.AXClasses.NativeUIElement AXButton None>]
但是,我为此添加了一个 cron 条目。
* * * * * sleep 10; python /Users/user/Desktop/test.py
当我跑步后
cat /tmp/test1.txt
[]
它返回空集。有人可以帮我为什么当我通过 cron 运行时没有检测到元素吗?
和权限有关吗?
【问题讨论】:
-
向脚本添加一些日志记录可能会很有用,以便查看发生了什么问题。您可以将此行添加到 cron 定义中:
* * * * * sleep 10; python /Users/user/Desktop/test.py >> /tmp/cron.log -
是的。我试着添加那个。我得到“切换是[]”。我确信 cron 正在触发。但这里的问题是,为什么它在通过 cron 运行时没有检测到 ui 元素?