Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add popuop handler example #10

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add popuop handler example
  • Loading branch information
Urvish Thakker authored and Urvish Thakker committed Feb 28, 2024
commit b33ab024d7d0000e45b0b91291fbd77604e16fe2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
| generalized query across sites | same_query_across_sites.py | [same_query_across_sites.py](https://github.com/tinyfish-io/fish-tank/blob/main/examples/same_query_across_sites/same_query_across_sites.py) |
| Save and reuse logged in state | save_and_load_context.py | [save_and_load_context.py](https://github.com/tinyfish-io/fish-tank/blob/main/examples/save_and_load_context/save_and_load_context.py) |
| Waiting for page to load | wait_for_entire_page_load.py | [wait_for_entire_page_load.py](https://github.com/tinyfish-io/fish-tank/blob/main/examples/wait_for_entire_page_load/wait_for_entire_page_load.py) |
| Default Popup Handler | default_popup_handler.py | [default_popup_handler.py](https://github.com/tinyfish-io/fish-tank/blob/main/examples/default_popup_handler/default_popup_handler.py) |
34 changes: 34 additions & 0 deletions examples/default_popup_handler/default_popup_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""This example demonstrates how to use the default popup handler to close all popups."""
import time
import webql

from webql.sync_api.web import PlaywrightWebDriver
from webql.sync_api import close_all_popups_handler

# Set the URL to the desired website
URL = "https://partakefoods.com/"

if __name__ == "__main__":
# Set headless to False to see the browser in action
driver = PlaywrightWebDriver(headless=False)

# Start a session with the specified URL and the custom driver
session = webql.start_session(URL, web_driver=driver)

# Define the queries to interact with the page
QUERY = """
{
search_btn
}"""

# Use the default popup handler to close all popups
session.on("popup", close_all_popups_handler)

# Make API call(s) to AgentQL server to fetch the query
response = session.query(QUERY)

# Wait for 2 seconds to see the browser in action
time.sleep(2)

# Stop the session
session.stop()