Create a new Python file amazon_shopping.py and add the following code:
Copy
Ask AI
from askui import VisionAgentimport loggingfrom askui import locators as locfrom askui.reporting import SimpleHtmlReporter# Initialize your agent with logging and reportingwith VisionAgent( log_level=logging.DEBUG, reporters=[SimpleHtmlReporter()]) as agent: # Open Amazon website agent.tools.webbrowser.open_new("http://www.amazon.com") agent.wait(3) # Wait for page to load # Search for a product agent.click(loc.Element("textfield")) agent.type("nike shoes") agent.keyboard('enter') agent.wait(2) # Wait for search results # Verify page contents page_status = agent.get("Are Nike shoes visible on the screen?") print(f"Cart Status: {page_status}")
# Using text locatoragent.click(loc.Text("Search"))# Using relative positioningsearch_icon = loc.Element().right_of(loc.Element("textfield"))agent.click(search_icon)
from askui import ResponseSchemaBaseclass ProductInfo(ResponseSchemaBase): name: str price: float rating: floatproduct = agent.get( "What is the name, price, and rating of the first product?", response_schema=ProductInfo)print(f"Found: {product.name} - ${product.price} ({product.rating} stars)")