此測試腳本是複製我的問題的確切場景。通過終端但不與cron通信的腳本
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元素? – srinath