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.
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
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.
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.
Related content
Example Python Script
This example shows how to use AgentQL's
get_by_promptmethod to retrieve an element and interact with it.Example JavaScript Script
This example shows how to use AgentQL's
get_by_promptmethod to retrieve an element and interact with it.Fetch a collection of elements with
query_elementsHow to use AgentQL's
query_elementsmethod to locate more than one element from a web page and perform automations with them.Scraping data with
query_dataLearn how to use the
query_datamethod to scrape and extract structured data from a website using AgentQL.