Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python保存使用selenium生成的日志_Python_Selenium_Webdriver - Fatal编程技术网

如何使用python保存使用selenium生成的日志

如何使用python保存使用selenium生成的日志,python,selenium,webdriver,Python,Selenium,Webdriver,我正在使用web驱动程序2.20并创建了自动化套装。不像 selenium RC(get_log函数)我想不出要保存的命令 生成的日志。 我试过: FirefoxProfile p = new FirefoxProfile(); p.setPreference("webdriver.log .file", "/tmp/firefox_console"); WebDriver driver = new FirefoxDriver(p); 但是找不到与python等效的。 也。。。 这也

我正在使用web驱动程序2.20并创建了自动化套装。不像 selenium RC(get_log函数)我想不出要保存的命令 生成的日志。 我试过:

FirefoxProfile p = new FirefoxProfile();   
p.setPreference("webdriver.log .file", "/tmp/firefox_console"); 
WebDriver driver = new FirefoxDriver(p); 
但是找不到与python等效的。 也。。。 这也是用java实现的。我还看到“导入日志”功能不知道 如何使用它将日志保存到文件中。
有什么建议吗?

以下内容也会对您有所帮助。python代码没有内部日志

from selenium import webdriver

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

谢谢,设置后它工作正常:

p.set_preference("webdriver.log.file", "/tmp/firefox_console")
将在您的项目工作区创建一个日志文件,您可以对其进行操作

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)