2012-05-25 35 views
6

我正在使用網絡驅動程序2.20並創建自動化套裝。不像 硒RC(get_log函數)我想不通的命令保存 生成的日誌。 我曾嘗試過:如何使用python保存使用硒生成的日誌

FirefoxProfile p = new FirefoxProfile(); 
p.setPreference("webdriver.log .file", "/tmp/firefox_console"); 
WebDriver driver = new FirefoxDriver(p); 

但找不到python等價物。 也http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/sel ... 這也是在java中。另外我看到「導入日誌記錄」功能不知道 如何使用它將日誌保存在文件中。 有什麼建議嗎?

回答

7

以下內容對您也是如此。 Python代碼沒有內部日誌。

from selenium import webdriver 

p = webdriver.FirefoxProfile() 
p.set_preference("webdriver.log.file", "/tmp/firefox_console") 
driver = webdriver.Firefox(p) 
2

由於其設置後的工作:

p.set_preference("webdriver.log.file", "/tmp/firefox_console") 
0
logfile = 'logs' + os.sep + ((__file__.upper())[(__file__.rfind(os.sep)+1):]).replace('.PY', '.log') 
logging.basicConfig(format= '%(asctime)-12s [%(filename)-10s] %(levelname)s %(message)s', 
datefmt='%Y-%m-%d %H:%M:%S', filename=logfile, filemode='w', level=logging.INFO) 

將建立在項目工作空間日誌文件,你可以在

工作
相關問題