Search code examples
pythonseleniumgoogle-colaboratory

Not working while Selenium in Google colaboratory(no new chrome pop up)


I have a trouble in Selenium on Google Colaboratory.

I have tried to auto-login for a portal site in my country. I learned that when I run the code, then new chrome window should be opened.

But I ran the code below, nothing happened even without error message.

!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)

wd.get("https://nid.naver.com/nidlogin.login")

sleep(0.5)
wd.find_element_by_name('id').send_keys('ID')
sleep(0.5)
wd.find_element_by_name('pw').send_keys('password')

Running finished but I didn't have any results... How can I get a new window?


Solution

  • Google Colaboratory runs code on server and Chrome runs on server too - so Chrome can display only on monitor connected to this server and you can't see this monitor. And there is no option to redirect image from server's monitor to your monitor - to Google Colaboratory's window on your monitor.


    If you will run it on your computer then you will not see Chrome because you use the option "--headless" which means "not display window". It is often used on servers because the server usually doesn't have a monitor (server is called "headless server" because the monitor looks like a computer's head), and the user couldn't see this monitor.

    With option "--headless" Chrome doesn't have to render and display page so it may also work faster. This option can be useful even on a local computer.