Skip to content

[BUG]FileChooser does not work. #1530

@rffanlab

Description

@rffanlab

Context:

  • Playwright Version: 1.25.1
  • Operating System: win11 and macOS birth
  • Python version: 3.8
  • Browser: Chromium

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally.

        with sync_playwright() as p:
            self.browser = p.chromium.launch_persistent_context(user_data_dir=root_path+"/components/chromedata",headless=self.headless,ignore_default_args=["--inPrivate"])
            # self.context = self.browser.new_context(
            #     user_agent=USER_AGENT,accept_downloads=True,locale="zh-CN"
            # )
            self.page = self.browser.new_page()
            self.page.goto(url=pageUrl)
            for item in actionList:
                if "sleep" in item:
                    time.sleep(item["sleep"])
                self.page.wait_for_selector(item["selector"])
                pageElement = self.page.locator(item["selector"])
                if "click" == item["action"]:
                    pageElement.click()
                if "filechooser" == item["action"]:
                    pageElement.click()
                    # self.page.pause()
                    # 无法监控到爱奇艺的上传窗口。
                    self.page.on("filechooser", lambda file_chooser: file_chooser.set_files("/Users/fangluyu/tmp/Waves-70796.mp4"))

            self.page.close()
            self.browser.close()

186347353-41c7f85d-d352-4f6b-8c2d-4fcdcd5f5dce

When start Using page.on("filechooser") it seems does not work for me. It failed to set file to filechooser

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions