Search
⌃K

How can I use Selenium?

Chrome WebDriver

From August 2021, the use of the Free plan's Chrome process becomes a reason for blocking the service policy and may cause the sanctioning of the use of the service.

Follow the instructions below to install Selenium, Chrome, ChromeDriver.

Install Selenium

pip3 install selenium

Install Chrome

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
apt-get update
apt-get install -y google-chrome-stable

Install ChromeDriver

It is necessary to install the ChromeDriver of a version that is compatible with the Chrome version installed in the previous step. Please follow the instructions below to check the Chrome version and install the correct version of the ChromeDriver.

Check the Chrome version

google-chrome --version

Check the ChromeDriver version to be installed

Download the ChromeDriver

You can download the ChromeDriver via the following terminal command. Replace the text [ChromeDriver Version] with the version number you checked in the previous step.
wget -N https://chromedriver.storage.googleapis.com/[ChromeDriver Version]/chromedriver_linux64.zip
What is expected to seem like when the download is completed

Install the ChromeDriver

Enter the following command to complete the installation of the downloaded ChromeDriver.
unzip chromedriver_linux64.zip
chmod +x chromedriver
mv -f chromedriver /usr/local/share/chromedriver
ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
rm chromedriver_linux64.zip
apt-get update
apt-get install -y libgconf-2-4

Python code example

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(options=options)
driver.get('https://google.com')
driver.quit()
When using the headless option as above, it is normal that a new window of the Chrome browser does not appear. Since the goormIDE container is an environment without a display, you must use the headless option when using Selenium.