diff --git a/playwright/_impl/_set_input_files_helpers.py b/playwright/_impl/_set_input_files_helpers.py index 0f40d5b99..65307e0a2 100644 --- a/playwright/_impl/_set_input_files_helpers.py +++ b/playwright/_impl/_set_input_files_helpers.py @@ -14,6 +14,7 @@ import base64 import collections.abc import os +import stat from pathlib import Path from typing import ( TYPE_CHECKING, @@ -144,7 +145,8 @@ def resolve_paths_and_directory_for_input_files( local_paths: Optional[List[str]] = None local_directory: Optional[str] = None for item in items: - if os.path.isdir(item): + item_stat = os.stat(item) # Raises FileNotFoundError if doesn't exist + if stat.S_ISDIR(item_stat.st_mode): if local_directory: raise Error("Multiple directories are not supported") local_directory = str(Path(item).resolve()) diff --git a/tests/sync/test_locators.py b/tests/sync/test_locators.py index b554f0544..49d4d46ae 100644 --- a/tests/sync/test_locators.py +++ b/tests/sync/test_locators.py @@ -327,6 +327,12 @@ def test_locators_should_upload_a_file(page: Page, server: Server) -> None: ) +def test_locators_upload_nonexistant_file(page: Page, server: Server) -> None: + page.goto(server.PREFIX + "/input/fileupload.html") + with pytest.raises(FileNotFoundError): + page.locator("input[type=file]").set_input_files("nonexistant.html") + + def test_locators_should_press(page: Page) -> None: page.set_content("") page.locator("input").press("h")