How to setup Selenium on a Linux VM by Zhum

https://towardsdatascience.com/how-to-setup-selenium-on-a-linux-vm-cd19ee47d922

Installation

To get selenium and Chromedriver running on your local machine, it can be broken down into 3 simple steps:

  1. Install dependencies
  2. Install Chrome binary and Chromedriver
  3. Install Selenium
sudo apt-get update
sudo apt-get install -y unzip openjdk-8-jre-headless xvfb libxi6 libgconf-2-4
# Install Chrome.

sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add

sudo echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list

sudo apt-get -y update
sudo apt-get -y install google-chrome-stable
# Install ChromeDriver.

wget -N https://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip -P ~/

unzip ~/chromedriver_linux64.zip -d ~/

rm ~/chromedriver_linux64.zip

sudo mv -f ~/chromedriver /usr/local/bin/chromedriver

sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
# Install Selenium
pip install selenium
Testando o scripts
from selenium import webdriver
from selenium.webdriver.chrome.options import OptionsCHROMEDRIVER_PATH = '/usr/local/bin/chromedriver'
WINDOW_SIZE = "1920,1080"chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.add_argument('--no-sandbox')driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,
                          chrome_options=chrome_options
                         )
driver.get("https://www.google.com")
print(driver.title)
driver.close()

Quando trava o sudo-apt upgrade…

E: Não foi possível obter trava /var/lib/dpkg/lock-frontend – open (11: Recurso temporariamente indisponível)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?

SOLUÇÃO:

sudo rm /var/lib/apt/lists/lock
sudo rm /var/lib/dpkg/lock
sudo rm /var/lib/dpkg/lock-frontend
sudo rm /var/cache/apt/archives/lock
sudo dpkg –configure -a
sudo apt-get upgrade -y

Couldn’t connect to Docker daemon at http+docker://localhost – is it running? If it’s at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

SOLUTION
sudo chown $USER /var/run/docker.sock

Instalar e configurar o NVM no linux (substituto do npm)

Primeiro baixar o repositório

 

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

 

Depois em uma nova aba instalar o NodeJS e outras coisas

 

nvm install 9

 

Se quiser pode instalar outra versão do Node, digamos a 8

 

nvm install 8

 

Para usar

 

nvm use 9 ou nvm use 8