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

前端 未结 6 1798
执笔经年
执笔经年 2021-01-02 06:14

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?

相关标签:
6条回答
  • 2021-01-02 06:39

    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()
    
    0 讨论(0)
  • 2021-01-02 06:39

    If it all for some reason does not work. (which was the case in our case). then go to this (relative) directory:

    C:\Users\yourname\AppData\Local\Programs\Python\Python38\Lib\site-packages\SeleniumLibrary\keywords\webdrivertools

    there is a file called: webdrivertools.py on line 157 you can edit

    service_log_path='./robots/robotsiot/Results/Results/Results/geckoresults', executable_path=executable_path,
    

    advantages: #1 if you're using something like Github and you synchronize a directory then the log files are kept separate. #2 the original file of the previous run gets overwritten (if that is what you want, but in some cases that is exactly how you need it).

    note: the section written above is in case you're using FireFox, if you are using another browser you'll have to edit it on a different line. note2: this path overrides on a high level, so arguments in Eclipse->Robot framework will not have any effect anymore.

    use this option with caution: it's sort of a last resort if the other options don't work!

    0 讨论(0)
  • 2021-01-02 06:49

    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
    0 讨论(0)
  • 2021-01-02 06:52

    No @hidehara, but I found a way how to do it. I looked up the file init in the Selenium2Library directory. in my case: C:\Users\Eigenaardig\AppData\Local\Programs\Python\Lib\site-packages\SeleniumLibrary

    there I added these 2 lines...

    from selenium import webdriver
    driver = webdriver.Firefox(executable_path=r'C:\Users\Eigenaar\eclipse-workspace\test\test\geckodriver.exe', log_path='./Log/geckodriver.log')
    

    created the directory LOG (in Windows Explorer)

    helaas, that started 2 instances.

    0 讨论(0)
  • 2021-01-02 06:55

    I added in a separate library (.py file)

    which looks like this (for test purposes):

    import time
    import random
    
    from selenium import webdriver
    driver = webdriver.Firefox(executable_path=r'C:\Users\specimen\RobotFrameWorkExperienced\RobotLearn\Log\geckodriver.exe', service_log_path='./Log/geckodriver.log')
    
    class CustomLib:
        ROBOT_LIBRARY_SCOPE = 'RobotLearn'
    
        num = random.randint(1, 18)
    
        if num % 2 == 0:
            def get_current_time_as_string(self):
                localtime = time.localtime()
                formatted_time = time.strftime("%Y%m%d%H%M%S", localtime)
                return formatted_time
        else:
            def get_current_time_as_string(self):
                localtime = time.localtime()
                formatted_time = time.strftime("%S%m%d%H%M%Y", localtime)
                return formatted_time
    

    But now it opens up 2 instances, 1 runs correct, 1 stays open and does nothing furthermore.

    help help.

    0 讨论(0)
  • 2021-01-02 06:59

    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()
    
    0 讨论(0)
提交回复
热议问题