0

I made a small bot on windows with selenium in java, I'm trying to export it on a linux vps with ubuntu installed.

(I exported from Windows Chrome profile (default) to Linux Vps profile directory but it doesn't work)

However, this function (which worked locally on windows) to load a specific chrome profile does not work for me.

This is a screenshot of Chrome Profile (Aapanel):

This is a screenshot of the app directory launching the command line

This is a screenshot of Chromium dir

This is my code:

import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import io.github.bonigarcia.wdm.WebDriverManager;
import java.io.File;
import org.apache.commons.io.FileUtils;

import org.openqa.selenium.OutputType;

public class App {
    public static void main(String[] args) throws Exception {

        // System.setProperty("webdriver.chrome.driver", "/usr/bin/chromedriver");
        //or
        WebDriverManager.chromedriver().setup();// setup automatico e aggiornato dei driver di google chrome

        WebDriver browser;
        ChromeOptions options = new ChromeOptions();

        // first line
        options.addArguments("--user-data-dir=/home/ubuntu/.config/google-chrome/");
        //second line
        options.addArguments("--profile-directory=Default");

        // without the above lines of code, it works (from here on down)
        options.addArguments("--headless");
        options.addArguments("--no-sandbox");
        // options.addArguments("--disable-gpu"); //funziona anche se attivata
        options.addArguments("--disable-dev-shm-usage");
        options.addArguments("--disable-infobars");
        options.addArguments("--remote-allow-origins=*");

        browser = new ChromeDriver(options);
        browser = new ChromeDriver(options);

        browser.get("https://www.instagram.com");

        //takeSnapShot(browser, "/www/wwwroot/lorenzo/SCREEEN/fanculo1.jpg");     


        Thread.sleep(3000);
        System.out.println("Fatto ora chiudi");
        browser.quit();

    }

At the precise moment in which I eliminate the first line and the second commented out of code does not give any error.

Searching on other forums I have already verified that the versions of chromedriver and google chrome installed match:

~$ chromedriver --version
ChromeDriver 111.0.5563.64 (c710e93d5b63b7095afe8c2c17df34408078439d-refs/branch-heads/5563@{#995})
~$ chromium --version
Chromium 111.0.5563.64 snap
~$ google-chrome --version
Google Chrome 111.0.5563.110

This is the error it gives me:

$ java -jar demo.jar

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 111.0.5563.64 (c710e93d5b63b7095afe8c2c17df34408078439d-refs/branch-heads/5563@{#995}) on port 11341
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session.
Response code 500. Message: unknown error: failed to write prefs file 
Host info: host: 'vps-44b9f1aa', ip: '127.0.1.1'
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-67-generic', java.version: '19.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--user-data-dir=/home/ubunt..., --profile-directory=Profile_1, --headless, --no-sandbox, --disable-dev-shm-usage, --disable-infobars, --remote-allow-origins=*], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--user-data-dir=/home/ubunt..., --profile-directory=Profile_1, --headless, --no-sandbox, --disable-dev-shm-usage, --disable-infobars, --remote-allow-origins=*], extensions: []}}}]
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
        at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:82)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:71)
        at com.example.App.main(App.java:38)

I rely on you! Thanks to whoever will help me, sorry for my poor english.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
  • Did you check read and write permissions at `home/ubuntu/.config/google-chrome/` ? Also, make sure you have enough space on your disk :) – kaliiiiiiiii Mar 22 '23 at 19:44
  • @kaliiiiiiiii Hi dear, I changed the permissions to the "Default" folder and now it doesn't give me any errors, thank you very much! – Lorenzo Mieli Mar 22 '23 at 20:24

0 Answers0