-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpushSetReady.py
More file actions
81 lines (63 loc) · 3.02 KB
/
pushSetReady.py
File metadata and controls
81 lines (63 loc) · 3.02 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import asyncio
from sys import argv
from pyppeteer import launch
# Example usage
username = argv[1]
password = argv[2]
print (f"Username: {username}")
print (f"Password: {password}")
async def login_to_prusa_connect(username, password):
browser = await launch(headless=True) # Set to True to run headless
page = await browser.newPage()
await page.setViewport({'width': 1920, 'height': 1080})
# Navigate to the login page
await page.goto('https://connect.prusa3d.com/login')
# Wait for the username input to appear and type the username
await page.waitForSelector('input[name="email"]')
await page.type('input[name="email"]', username)
# # Wait for the password input to appear and type the password
await page.waitForSelector('input[name="password"]')
await page.type('input[name="password"]', password)
# # Click the login button
await page.click('button[type="submit"]')
# Wait for navigation to complete
await page.waitForNavigation()
print("Logged in!")
button_xpath = '//button[contains(text(), "I am OK with that")]'
while True:
try:
# Wait for the button to appear
await page.waitForXPath(button_xpath, timeout=5000)
# Get the list of buttons matching the XPath
buttons = await page.xpath(button_xpath)
if buttons:
button = buttons[0] # Use the first matching button
# Check if the button is enabled
disabled = await page.evaluate('(btn) => btn.disabled', button)
if not disabled:
# Click the button
await button.click()
match button_xpath:
case '//button[contains(text(), "I am OK with that")]':
print("Clicked 'I am OK with that'")
button_xpath = '//button[.//div[contains(text(), "Set ready")]]'
case '//button[.//div[contains(text(), "Set ready")]]':
print("Clicked 'Set ready'")
button_xpath = '//button[.//div[contains(text(), "Confirm")]]'
case '//button[.//div[contains(text(), "Confirm")]]':
print("Clicked 'Confirm'")
await asyncio.sleep(5)
button_xpath = '//button[.//div[contains(text(), "Set ready")]]'
case _:
continue
else:
print("Button is disabled. Retrying...")
else:
print("Button not found. Retrying...")
except asyncio.TimeoutError:
print("Button not found within timeout. Retrying...")
except Exception as e:
print(f"An error occurred: {e}")
# Wait before retrying
await asyncio.sleep(1) # Adjust the sleep duration as needed
asyncio.get_event_loop().run_until_complete(login_to_prusa_connect(username, password))