forked from hargup/visbrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
32 lines (25 loc) · 947 Bytes
/
quickstart.py
File metadata and controls
32 lines (25 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from playwright.sync_api import sync_playwright
def click(page, text):
# Find an element containing the specified text and click on it
element = page.locator(f"text={text}").first
if element.count() == 0:
print(f"No element found with text '{text}'")
return False
element.click()
print(f"Clicked on element with text '{text}'")
return True
def main():
# Initialize Playwright and start a browser
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
page.goto("https://paulgraham.com/index.html")
text_to_click = "How to Start Google"
success = click(page, text_to_click)
if not success:
print("Failed to click on the element.")
page.wait_for_timeout(3000)
# Close the browser
browser.close()
if __name__ == "__main__":
main()