LLM on TagUI RPA and Python rpa package - see responses from Claude LLM
kensoh opened this issue · 0 comments
AI and machine learning (in particular LLM - large language models) could be useful to help generate scripts for RPA.
See the following questions that I asked Anthropic's Claude 3.5 Sonnet and its responses. I think it could be useful for some users to generate the template code, and make modifications accordingly. Or convert TagUI scripts to Python.
Question 1
write a Python rpa package script to do google search for rpa and capture screenshot of the search results
Response 1
Here's a Python script that uses the RPA (Robotic Process Automation) package to perform a Google search for "rpa" and capture a screenshot of the search results:
import rpa as r
import time
# Initialize the RPA
r.init()
try:
# Open Google in the default browser
r.url('https://www.google.com/')
# Wait for the page to load
time.sleep(2)
# Enter the search term and submit
r.type('//*[@name="q"]', 'rpa[enter]')
# Wait for the search results to load
time.sleep(3)
# Capture a screenshot of the search results
r.snap('page', 'rpa_search_results.png')
print("Screenshot captured successfully.")
except Exception as e:
print(f"An error occurred: {str(e)}")
finally:
# Close the browser and end the RPA session
r.close()
Question 2
write a TagUI RPA script to do google search for rpa and capture screenshot of the search results
Response 2
Here's a TagUI RPA script that performs a Google search for "rpa" and captures a screenshot of the search results:
// Navigate to Google
https://www.google.com/
// Wait for the page to load
wait 3
// Type "rpa" into the search box and press Enter
type q as rpa
enter
// Wait for search results to load
wait 3
// Capture a screenshot of the search results
snap page to rpa_search_results.png
// Print a message to confirm the screenshot was taken
echo Screenshot captured successfully.
Question 3
convert attached TagUI RPA script to Python rpa package script
https://www.google.com
type q as rpa[enter]
click Search
for item 1 to 50
show (XPath)[`item`]
for (i = 0; i < 50; i++) {
echo `i`
}
Response 3
I'll convert the provided TagUI RPA script to a Python script using the RPA package. Here's the converted script:
import rpa as r
import time
# Initialize the RPA
r.init()
try:
# Navigate to Google
r.url('https://www.google.com/')
# Wait for the page to load
time.sleep(2)
# Type "rpa" into the search box and press Enter
r.type('//*[@name="q"]', 'rpa[enter]')
# Wait for search results to load
time.sleep(2)
# Click the Search button (if needed)
r.click('Search')
# Loop through items 1 to 50 and show XPath
for item in range(1, 51):
xpath = f'(//*)[{item}]'
element_text = r.read(xpath)
print(f"Item {item} XPath: {xpath}")
print(f"Element text: {element_text}")
# Loop from 0 to 49 and echo the number
for i in range(50):
print(i)
except Exception as e:
print(f"An error occurred: {str(e)}")
finally:
# Close the browser and end the RPA session
r.close()
Question 4
write a Python rpa package script to login to Xero and print the account statement for the past 12 months from a given date
Response 4
Here's a Python script using the RPA package to log in to Xero and print the account statement for the past 12 months from a given date:
import rpa as r
from datetime import datetime, timedelta
import time
# Initialize the RPA
r.init()
# Xero login credentials
xero_email = "[your_email@example.com](mailto:your_email@example.com)"
xero_password = "your_password"
# Date for the end of the 12-month period (format: YYYY-MM-DD)
end_date = "2024-08-27"
try:
# Navigate to Xero login page
r.url('https://login.xero.com/')
time.sleep(3)
# Enter email and password
r.type('//*[@id="xl-form-email"]', xero_email)
r.type('//*[@id="xl-form-password"]', xero_password)
r.click('Log in')
time.sleep(5)
# Navigate to the Reports section
r.click('Reports')
time.sleep(2)
r.click('All Reports')
time.sleep(2)
# Find and click on Account Statement
r.click('Account Statement')
time.sleep(3)
# Set the date range
end_date = datetime.strptime(end_date, "%Y-%m-%d")
start_date = end_date - timedelta(days=365)
r.type('//*[@id="fromDate"]', start_date.strftime("%d %b %Y"))
r.type('//*[@id="toDate"]', end_date.strftime("%d %b %Y"))
# Update the report
r.click('Update')
time.sleep(5)
# Print the report
r.click('Print')
time.sleep(3)
# In the print dialog, you might need to select the appropriate printer
# and click the final print button. This part may vary depending on your system.
# You might need to use r.click() or r.type() to interact with the print dialog.
print("Account statement printed successfully.")
except Exception as e:
print(f"An error occurred: {str(e)}")
finally:
# Close the browser and end the RPA session
r.close()