Fetch a collection of elements with query_elements
You can use the query_elements
method to locate more than one element from a web page. You can use these elements to automate workflows and interact with web sites by simulating clicking on buttons, filling out form fields, and scrolling.
Overview
This guide shows you how to return one or more elements with query_elements
and how to use it in your scripts to interact with web elements.
Define a query
The first step is to define a query for all the desired elements you want AgentQL to return.
In this example, the goal is to interact with the add_to_cart_button
.
Fetch an element with query_elements
Next, pass the query to the query_elements
method to fetch the desired elements.
Access an element returned by query_elements
query_elements
returns a Python object you can use to interact with the elements on the page. You can access the elements as if they were the fields of this response object.
Fetch multiple elements with query_elements
This query returns all the products on the page and their "add to cart" buttons.
Extract a single element from many
Conclusion
query_elements
is the proper method to use when you want to interact with multiple elements on a page. If you only need to a single element, use the get_by_prompt
method instead.