Ruby關閉IE進程采用直接關閉進程法
作者:佚名
Ruby關閉IE進程再實際應用中是經常會遇到的問題。對于剛剛接觸Ruby語言的朋友來說可能還對其不是太了解。希望通過我們的介紹大家可以充分掌握這一技巧的應用。
在Ruby語言的實際是代碼編寫中,我們會覺得它的編寫方式不同于其他語言,并且在編寫代碼時會有一種非常愉悅的心情。在這里我們就為大家介紹一下Ruby關閉IE進程的相關方法。#t#
使用watir的close_all方法,有時會關閉不掉IE,***的Ruby關閉IE進程辦法就是直接終止IE進程,可以寫一個關閉ie的方法
- require 'win32ole'
- # Returns the number
of windows
processes running with
the specified name. - def close_ie
- mgmt = WIN32OLE.connect
('winmgmts:\\\\.') - processes=mgmt.
instancesof("win32_process") - processes.each do |process|
- puts process
- if process.name ==
"iexplore.exe" then - process.terminate()
- end
- end
- end
這樣調用close_ie方法時就可以實現Ruby關閉IE進程了。
責任編輯:曹凱
來源:
博客園