_file_chooser.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (c) Microsoft Corporation.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from pathlib import Path
  15. from typing import TYPE_CHECKING, Sequence, Union
  16. from playwright._impl._api_structures import FilePayload
  17. if TYPE_CHECKING: # pragma: no cover
  18. from playwright._impl._element_handle import ElementHandle
  19. from playwright._impl._page import Page
  20. class FileChooser:
  21. def __init__(
  22. self, page: "Page", element_handle: "ElementHandle", is_multiple: bool
  23. ) -> None:
  24. self._page = page
  25. self._loop = page._loop
  26. self._dispatcher_fiber = page._dispatcher_fiber
  27. self._element_handle = element_handle
  28. self._is_multiple = is_multiple
  29. def __repr__(self) -> str:
  30. return f"<FileChooser page={self._page} element={self._element_handle}>"
  31. @property
  32. def page(self) -> "Page":
  33. return self._page
  34. @property
  35. def element(self) -> "ElementHandle":
  36. return self._element_handle
  37. def is_multiple(self) -> bool:
  38. return self._is_multiple
  39. async def set_files(
  40. self,
  41. files: Union[
  42. str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload]
  43. ],
  44. timeout: float = None,
  45. noWaitAfter: bool = None,
  46. ) -> None:
  47. await self._element_handle.set_input_files(files, timeout, noWaitAfter)