Skip to content

[πŸ› Bug]: setDownloadPath should not check folder stats when using a remote WebDriver serverΒ #14064

@rafaelmfonseca

Description

@rafaelmfonseca

What happened?

I'm using the selenium/standalone-chrome Docker image to set up a Selenium Grid with Chrome for running WebDriver tests remotely. This container is hosted on a separate machine (let's call it Computer A), but the application calling the remote WebDriver it's on a different server (Computer B).

When I attempt to call setDownloadPath from Computer B, it fails because it verifies if the folder exists on Computer B. However, the actual download occurs on Computer A, where the folder doesn't exist on Computer B.

I currently solve this problem by sending the Page.setDownloadBehavior command directly to DevTools:

import { Driver } from 'selenium-webdriver/chrome';
await (driver as Driver).sendDevToolsCommand('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: '/home/seluser/Downloads/' });

(which is exactly what setDownloadPath does)

How can we reproduce the issue?

You need to setup two computers, first one using Selenium Grid:

version: "3.9"

services:
    selenium_chrome:
        container_name: selenium_chrome
        image: "selenium/standalone-chrome"
        user: root
        restart: always
        shm_size: 2g
        environment:
            SE_OPTS: "--port 3501"
            SE_NO_VNC_PORT: 3502
        volumes:
            - C:/downloads/:/home/seluser/Downloads/
            - C:/seprofile/:/home/seluser/.config/google-chrome/Default
        ports:
            - 3501:3501
            - 3502:3502
        networks:
            - my-selenium

networks:
    my-selenium:

Then the second one, with the node app. Build the remote driver, and later call setDownloadPath with a folder that does not exists on computer where the node app is running (but the folder only exists inside the container):

import { Options as ChromeOptions, Driver } from 'selenium-webdriver/chrome';
import { Builder, Browser, WebDriver } from 'selenium-webdriver';
import env from './core/env';

async function buildDriver(): Promise<WebDriver> {
    const options = new ChromeOptions();
    options.setPageLoadStrategy('eager');
    options.addArguments('--user-data-dir=/home/seluser/.config/google-chrome/');
    options.addArguments('--profile-directory=Default');

    /**
     * I know I can set the download path here by using:
     * options.setUserPreferences({
     *  "download.default_directory": "/home/seluser/Downloads/",
     * });
     * But this does not work for me because later I change
     * download path more than one time within the same session.
     */

    let builder = new Builder()
        .forBrowser(Browser.CHROME)
        .usingServer(env.SELENIUM_REMOTE_SERVER)
        .setChromeOptions(options);

    const driver = await builder.build();

    // command below throws an exception, but the folder exists inside selenium grid container, but not where the node app is running
    await (driver as Driver).setDownloadPath('/home/seluser/Downloads/');
    /* 
     * "ENOENT: no such file or directory, stat 'C:\\home\\seluser\\Downloads\\'"
     * stack:
     * "Error: ENOENT: no such file or directory, stat 'C:\\home\\seluser\\Downloads\\'"
     */

    return driver;
}

Error returned:

"ENOENT: no such file or directory, stat 'C:\\home\\seluser\\Downloads\\'"
stack:
"Error: ENOENT: no such file or directory, stat 'C:\\home\\seluser\\Downloads\\'"

Relevant log output

message:
"ENOENT: no such file or directory, stat 'C:\\home\\seluser\\Downloads\\'"
stack:
"Error: ENOENT: no such file or directory, stat 'C:\\home\\seluser\\Downloads\\'"

Operating System

Where Node App is hosted: Windows 11
Where Selenium Grid is:

Node Id: 
OS Arch: amd64
OS Name: Linux
OS Version: 5.15.133.1-microsoft-standard-WSL2
Total slots: 1
Grid version: 4.21.0 (revision 79ed462ef4)

Selenium version

4.21.0

What are the browser(s) and version(s) where you see this issue?

Chrome, 125.0.6422.76

What are the browser driver(s) and version(s) where you see this issue?

4.21.0

Are you using Selenium Grid?

Grid version: 4.21.0 (revision 79ed462)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!I-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions