Skip to main content

Frequently Asked Questions

Q. How do I debug my script

Ans: Since the release of version 0.5.0, AgentQL SDK has an internal debug mode, which is implemented as a context manager that can be wrapped around your script. Once a crash happens or the script finishes running, the debug mode will save the following contents to the folder path specified during the setup process or AGENTQL_DEBUG_PATH environment variable (default path is $HOME/.agentql/debug):

  1. Log of each action taken by AgentQL SDK.
  2. Error information (if the script crashes).
  3. Screenshot of each page on which a query action is performed.
  4. Accessibility Tree of the last page before the crash or the end of script.
  5. Meta information (OS, Python version, AgentQL version).

The following script is an example of how you can use this debug mode:

import logging

import agentql
from agentql.sync_api import DebugManager

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)

QUERY = """
{
search_box
search_btn
about_link
}
"""


# The following context manager will enable debug mode for the script.
with DebugManager.debug_mode():
session = agentql.start_session("https://www.google.com")

log.debug("Analyzing...")

response = session.query(QUERY)

log.debug("Entering text...")

# Buggy code that will crash the script. When it crashes, the debug manager will save debug files to designated directory ($HOME/.agentql/debug by default).
response.search.fill("tinyfish")

log.debug('Clicking "Search" button...')
response.search_btn.click(force=True)

session.stop()

Q. While writing AgentQL Script, how do I ensure the web page is loaded entirely

Ans: Loading web page entirely right now is considered as an application logic, as it is difficult to objectively tell what does it mean that entire web page is loaded. As some websites have lazy loading and are infinitely scroablle and so for those kind of web pages what does it mean to load the entire web page.

Thus, right now we give this ability to users to decide and choose how much they would like to scroll. By default we scroll 3 pages and we expose APIs scroll_up(px: Optional = 720) and scroll_down(px: Optional = 720) for users to decide how and when they would like to scroll in their AgentQL script.

Q. How do I make sure that my script waits enough for all the element to appear on the page

Ans: The interim solution for this if you run into this issue is addding sleep() to your code. Following is a sample script and usage of sleep to depict how it could be leveraged. You could add sleep based on your requirements. You can approximately set the sleep timeout as of now.

import time
import agentql

QUERY = """
{
search_box
videos[] {
related_video_name
}
}
"""

time.sleep(5)
session = agentql.start_session("https://www.youtube.com/watch?v=qQkBeOisNM0")
response = session.query(QUERY)

try:
log.debug(f"Successfully received AgentQL: \n{response}")
response.search_box.fill("tinyfish")
response.search_btn.click(force=True)
except Exception as e:
log.error(f"Found Error: {e}")

session.stop()