Fetch a single element with get_by_prompt

You can use the get_by_prompt method to locate one or more elements from a web page by passing context, a prompt describing the element you're looking for. You can use this element to automate workflows and interact with web sites by simulating clicking on buttons, filling out form fields, and scrolling.

caution

Unlike query_data(scraping), get_by_prompt doesn't return data but one or more interactive Playwright locators.

Overview

This guide shows you how to return an element with get_by_prompt and how to use it in your scripts to interact with web elements.

Pass a prompt to get_by_prompt

example.py
python
search_bar = page.get_by_prompt("the search bar")

Access an element returned by get_by_prompt

get_by_prompt returns a Python object you can use to interact with the element on the page. You can access the element as if they were the fields of this response object.

example.py
python
search_bar.fill("AgentQL")

Conclusion

get_by_prompt is the proper method to use when you want to interact with a single element on a page. If you need to access multiple elements or want to make one call to return multiple locators, use the query_elements method instead.