简体   繁体   中英

Can we run selenium test in non-headless mode in linux?

I knew and it is working fine also with headless mode on linux(python+selenium), for headless mode

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        browser = webdriver.Chrome(webdriver_manager.chrome.ChromeDriverManager().install(),
                                   chrome_options=chrome_options)

My requirement: Want to run selenium/python script without headless chrome mode(ie non-headless) But when i comment or remove line (--headless),

        chrome_options = webdriver.ChromeOptions()
        #chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        browser = webdriver.Chrome(webdriver_manager.chrome.ChromeDriverManager().install(),
                                   chrome_options=chrome_options)

or even (--no-headless)

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--no-sandbox')
        browser = webdriver.Chrome(webdriver_manager.chrome.ChromeDriverManager().install(),
                                   chrome_options=chrome_options)

it gave me error with above (non-headless) change while running python script,

Looking for [chromedriver 84.0.4147.30 linux64] driver in cache
File found in cache by path [/***/drivers/chromedriver/84.0.4147.30/linux64/chromedriver]
Error in UI Test: local variable 'browser' referenced before assignment

Can someone help me to achieve this requirement, if possible in linux?

If you aren't using --headless , ideally you should remove the following argument as well:

chrome_options.add_argument('--no-sandbox')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM