autogen_ext.agents.web_surfer.playwright_controller#
- class PlaywrightController(downloads_folder: str | None = None, animate_actions: bool = False, viewport_width: int = 1440, viewport_height: int = 900, _download_handler: Callable[[Download], None] | None = None, to_resize_viewport: bool = True)[source]#
基类:
object
一个辅助类,允许 Playwright 与网页交互,执行点击、填写和滚动等操作。
- 参数:
- async get_interactive_rects(page: Page) Dict[str, InteractiveRegion] [source]#
从网页中检索交互区域。
- 参数:
page (Page) – Playwright 页面对象。
- 返回:
Dict[str, InteractiveRegion] – 交互区域的字典。
- async get_visual_viewport(page: Page) VisualViewport [source]#
检索网页的可视视口。
- 参数:
page (Page) – Playwright 页面对象。
- 返回:
VisualViewport – 页面可视视口。
- async get_focused_rect_id(page: Page) str | None [source]#
检索当前聚焦元素的 ID。
- 参数:
page (Page) – Playwright 页面对象。
- 返回:
str – 聚焦元素的 ID,如果没有控件聚焦则为 None。
- async get_page_metadata(page: Page) Dict[str, Any] [source]#
从网页中检索元数据。
- 参数:
page (Page) – Playwright 页面对象。
- 返回:
Dict[str, Any] – 页面元数据的字典。
- async visit_page(page: Page, url: str) Tuple[bool, bool] [source]#
访问指定的 URL。
- 参数:
page (Page) – Playwright 页面对象。
url (str) – 要访问的 URL。
- 返回:
Tuple[bool, bool] – 一个元组,指示是否重置先前的元数据哈希和上次下载。
- async page_down(page: Page) None [source]#
向下滚动页面,滚动距离为视口高度减去 50 像素。
- 参数:
page (Page) – Playwright 页面对象。
- async page_up(page: Page) None [source]#
向上滚动页面,滚动距离为视口高度减去 50 像素。
- 参数:
page (Page) – Playwright 页面对象。
- async gradual_cursor_animation(page: Page, start_x: float, start_y: float, end_x: float, end_y: float) None [source]#
逐渐动画化光标从起始坐标到结束坐标的移动。
- async add_cursor_box(page: Page, identifier: str) None [source]#
在给定标识符的元素周围添加一个红色光标框。
- 参数:
page (Page) – Playwright 页面对象。
identifier (str) – 元素标识符。
- async remove_cursor_box(page: Page, identifier: str) None [source]#
移除给定标识符的元素周围的红色光标框。
- 参数:
page (Page) – Playwright 页面对象。
identifier (str) – 元素标识符。
- async click_id(page: Page, identifier: str) Page | None [source]#
点击给定标识符的元素。
- 参数:
page (Page) – Playwright 页面对象。
identifier (str) – 元素标识符。
- 返回:
Page | None – 如果打开新页面,则为新页面,否则为 None。
- async hover_id(page: Page, identifier: str) None [source]#
将鼠标悬停在给定标识符的元素上。
- 参数:
page (Page) – Playwright 页面对象。
identifier (str) – 元素标识符。
- async fill_id(page: Page, identifier: str, value: str, press_enter: bool = True) None [source]#
用指定值填充给定标识符的元素。
- async get_webpage_text(page: Page, n_lines: int = 50) str [source]#
检索网页的文本内容。
- 参数:
page (Page) – Playwright 页面对象。
n_lines (int) – 从页面内部文本返回的行数。
- 返回:
str – 页面的文本内容。