Selenium / webdriver error

I’m trying to perform Python automation using Selenium, but this log message appears:

INFO:root:Iniciando a automação...

May 26 03:30:59 PMINFO:root:Automação deu erro

May 26 03:30:59 PMCaminho do Chromium: /opt/render/project/src/chrome-win64/chrome.exe

May 26 03:30:59 PMCaminho do ChromeDriver: /opt/render/project/src/chromedriver-win64/chromedriver.exe

May 26 03:30:59 PMMessage: 'chromedriver.exe' executable may have wrong permissions.

May 26 03:30:59 PM

May 26 03:30:59 PM

I’m using the Chrome driver, and the browser itself downloaded directly from the repository, running the code locally, it runs normally without errors, running the automation without problems.

Hi,

There will always be differences between environments: development mode/Local, production mode/Render, etc. These differences need to be considered and configured as required for your own app in each environment.

It looks like you’re trying to use Windows binaries on Render, which uses Linux.

Installing Chrome/Chromium on Render Native Runtimes is covered in several community topics, e.g. https://community.render.com/t/installing-headless-chromium-w-o-docker/5185

Hello, fortunately I managed to install Google in the render, and applied it to the python code to use those in the render, however this message was displayed in the log when trying to run the automation:

INFO:root:Iniciando a automação...

May 29 09:28:58 AMINFO:root:Automação deu erro

May 29 09:28:58 AMCaminho do Google Chrome: /opt/render/project/.render/chrome/opt/google/chrome/google-chrome

May 29 09:28:58 AMCaminho do ChromeDriver: /opt/render/project/.render/chromedriver/chromedriver

May 29 09:28:58 AMMessage: session not created: This version of ChromeDriver only supports Chrome version 114

May 29 09:28:58 AMCurrent browser version is 125.0.6422.112 with binary path /opt/render/project/.render/chrome/opt/google/chrome/google-chrome

May 29 09:28:58 AMStacktrace:

I tried to download version 114 of Chrome but I couldn’t.

render-start.sh

#!/usr/bin/env bash
# exit on error
set -o errexit

STORAGE_DIR=/opt/render/project/.render

# Install dpkg if not already installed
if ! command -v dpkg &> /dev/null
then
  apt-get update && apt-get install -y dpkg
fi

# Download and install Google Chrome
if [[ ! -d $STORAGE_DIR/chrome ]]; then
  echo "...Downloading Chrome"
  mkdir -p $STORAGE_DIR/chrome
  cd $STORAGE_DIR/chrome
  wget -P ./ https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
  dpkg -x ./google-chrome-stable_current_amd64.deb $STORAGE_DIR/chrome
  rm ./google-chrome-stable_current_amd64.deb
  cd $HOME/project/src # Make sure we return to where we were
else
  echo "...Using Chrome from cache"
fi

# Download and install ChromeDriver
CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
if [[ ! -d $STORAGE_DIR/chromedriver ]]; then
  echo "...Downloading ChromeDriver"
  mkdir -p $STORAGE_DIR/chromedriver
  cd $STORAGE_DIR/chromedriver
  wget -P ./ "https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
  unzip chromedriver_linux64.zip
  rm chromedriver_linux64.zip
  cd $HOME/project/src # Make sure we return to where we were
else
  echo "...Using ChromeDriver from cache"
fi

# Add Chrome and ChromeDriver's location to the PATH
export PATH="${PATH}:/opt/render/project/.render/chrome/opt/google/chrome"
export PATH="${PATH}:/opt/render/project/.render/chromedriver"

# add your own build commands...

app.py

 try:
        # Caminho do Google Chrome instalado pelo script start.sh
        caminho_chrome = "/opt/render/project/.render/chrome/opt/google/chrome/google-chrome"
        caminho_chromedriver = "/opt/render/project/.render/chromedriver/chromedriver"

        # Verificar se o caminho do Google Chrome existe
        if os.path.exists(caminho_chrome):
            print("Caminho do Google Chrome:", caminho_chrome)
        else:
            raise FileNotFoundError(f"Caminho do Google Chrome não encontrado: {caminho_chrome}")

        # Verificar se o caminho do ChromeDriver existe
        if os.path.exists(caminho_chromedriver):
            print("Caminho do ChromeDriver:", caminho_chromedriver)
        else:
            raise FileNotFoundError(f"Caminho do ChromeDriver não encontrado: {caminho_chromedriver}")

        # Configurar as opções do Chrome
        logging.info("Iniciando a automação...")

        options = Options()
        options.binary_location = caminho_chrome

        options.add_argument("--headless")
        options.add_argument("--disable-gpu")
        options.add_argument("--no-sandbox")
        options.add_argument("--disable-dev-shm-usage")
        options.add_argument("--window-size=1920,1080")
        options.add_argument("--ignore-certificate-errors")
        options.add_argument("--allow-running-insecure-content")

        # Configurar o serviço do ChromeDriver
        service = Service(executable_path=caminho_chromedriver)

        # Iniciar o navegador Chrome usando o caminho do Chromium especificado
        navegador = webdriver.Chrome(service=service, options=options)

I downloaded the latest version of webdriver through Selenium, now it’s causing problems with xpath, little by little it’s progressing.

AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'