Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I relocate/disable GeckoDriver's log file in selenium, python 3?

Ahoy, how do I disable GeckoDriver's log file in selenium, python 3?

If that's not possible, how do I relocate it to Temp files?

like image 808
Menace Avatar asked May 01 '18 00:05

Menace


People also ask

What is Geckodriver log?

geckodriver provides different bands of logs for different audiences. The most important log entries are shown to everyone by default, and these include which port geckodriver provides the WebDriver API on, as well as informative warnings, errors, and fatal exceptions.


4 Answers

To relocate the GeckoDriver logs you can create a directory within your project space e.g. Log and you can use the argument log_path to store the GeckoDriver logs in a file as follows :

from selenium import webdriver

driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe', log_path='./Log/geckodriver.log')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
like image 70
undetected Selenium Avatar answered Oct 18 '22 20:10

undetected Selenium


ref: 7. WebDriver API > Firefox WebDriver

according to the documents, you can relocate it to Temp following:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options$
import os

options = Options()
driver = webdriver.Firefox(executable_path=geckodriver_path, service_log_path=os.path.devnull, options=options)

Following argument are deprecated:

  • firefox_options – Deprecated argument for options
  • log_path – Deprecated argument for service_log_path
like image 35
hidehara Avatar answered Oct 18 '22 20:10

hidehara


You should be using the service_log_path, as of today the log_path is deprecated, example with pytest:

@pytest.mark.unit
@pytest.fixture
def browser(pytestconfig):
    """
    Args:
        pytestconfig (_pytest.config.Config)
    """
    driver_name = pytestconfig.getoption('browser_driver')
    driver = getattr(webdriver, driver_name)
    driver = driver(service_log_path='artifacts/web_driver-%s.log' % driver_name)
    driver.implicitly_wait(10)
    driver.set_window_size(1200, 800)
    yield driver
    driver.quit()
like image 20
Evolter Avatar answered Oct 18 '22 20:10

Evolter


using WebDriver(log_path=path.devnull) and WebDriver(service_log_path=path.devnull are both deprecated at this point in time, both result in a warning.

using a service object is now the prefered way of doing this:

from os import path
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.webdriver import WebDriver

service = Service(log_path=path.devnull)
driver = WebDriver(service=service)

driver.close()
like image 3
aarondiel Avatar answered Oct 18 '22 22:10

aarondiel