How to save logs generated using selenium with python

I use the web driver 2.20 and created a machine. Unlike selenium RC (get_log function), I cannot define a command to save generated logs. I tried:

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

but cannot find python equivalent. Also http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/sel ... this is also in java. In addition, I saw that the log import function does not know how to save the logs in a file using it. Any suggestions?

+6
source share
3 answers

The following will do the same for you. There are no internal logs for python code.

 from selenium import webdriver p = webdriver.FirefoxProfile() p.set_preference("webdriver.log.file", "/tmp/firefox_console") driver = webdriver.Firefox(p) 
+7
source

Thank you for working after setup:

 p.set_preference("webdriver.log.file", "/tmp/firefox_console") 
+2
source
 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) 

will create a log file in the project workspace on which you can work

0
source

Source: https://habr.com/ru/post/916637/


All Articles