Use Selenium with Chromium Browser

前端 未结 6 1328
不知归路
不知归路 2020-12-05 10:50

In the Selenium options (on Firefox) I can find Custom browser.

Is it possible to use this option to run a Selenium test in Chromiu

6条回答
  •  误落风尘
    2020-12-05 11:31

    Yes, it is...

    In a Linux you can install, to use without a xwindow (ex.: in a webserver) too... Its nice to some tests.

    apt install chromium-shell 
    

    In a code, you'll need a chromedriver, look this:

    chromedriver

    In this case i'll use a python code, to open a chromium in a headless mode:

    def startBot():
        chrome_options = Options()
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-dev-shm-usage')
        driver = webdriver.Chrome('/opt/chromedriver85', options=chrome_options)
        #driver.set_window_size(1366, 728)
        #aguardar carregamento em segundos
        driver.implicitly_wait(5)
    
        print("get url...")
        driver.get("https://www.google.com")
    

    Obs.:

    A headless browser is a great tool for automated testing and server environments where you don't need a visible UI shell. (source)

    That's it!

提交回复
热议问题