Tuyệt vời! Hãy cùng đi qua ví dụ cụ thể với prompt bạn đưa ra, và cùng xem cách tách các hành động cụ thể rồi ánh xạ vào các phần tử DOM tương ứng.
✅ Prompt:
code
- Go to https://ipay.uillinois.edu/gar/logon.cfm
- Select pay invoices
- Select the E-Check payment method and submit
- Click all invoices and click continue
🧠 Bước 1: Phân tích logic/actions từ Prompt
STT
Câu lệnh trong Prompt
Loại hành động
Mục tiêu (target)
1
Go to https://ipay.uillinois.edu/gar/logon.cfm
NAVIGATE
URL
2
Select pay invoices
CLICK
"Pay Invoices"
3
Select the E-Check payment method and submit
SELECT, SUBMIT
"E-Check", sau đó click Submit
4
Click all invoices and click continue
CLICK, CLICK
check tất cả các hóa đơn, rồi click "Continue"
🖼️ Bước 2: Ví dụ giả lập DOM Tree tương ứng (BeautifulSoup style)
Giả sử bạn có dom_tree = BeautifulSoup(html, 'html.parser'), và DOM như sau:
✅ Action 3: "Click all invoices and click continue"
Tìm tất cả checkbox invoices
python
all_invoice_checkboxes = dom_tree.find_all('input', {'type': 'checkbox', 'name': 'invoice'})
print([checkbox['value'] for checkbox in all_invoice_checkboxes])
# --> ['12345', '67890', '99999']
Tìm nút Continue
python
continue_btn = dom_tree.find('button', string=lambda text: text and 'continue' in text.lower())
print(continue_btn['id']) # --> "continueBtn"
✅ Kết quả tương ứng – Tập hợp các element được ánh xạ
Action
Element tìm thấy
Selector
Ghi chú
Click "Pay Invoices"
<a id="payInvoicesBtn">
#payInvoicesBtn
Link
Select "E-Check"
<input id="echeck" type="radio"...>
#echeck
Radio button
Submit Payment
<button id="submitPaymentBtn">
#submitPaymentBtn
Submit button
Check all invoices
List <input type="checkbox" name="invoice"...>
[name="invoice"]
Multiple checkboxes
Click Continue
<button id="continueBtn">
#continueBtn
Button
🛠️ Tổng hợp bằng Python (giống hệ thống tự động truy vết từ prompt)
python
from bs4 import BeautifulSoup
# Giả sử bạn đã load được DOM:
dom_tree = BeautifulSoup(html_str, "html.parser")
# Các phần tử chính tương ứng
elements = {}
# 1. Pay Invoices
elements['pay_invoices'] = dom_tree.find(lambda tag: tag.name in ['a', 'button'] and 'pay invoices' in tag.get_text(strip=True).lower())
# 2. Chọn E-Check
elements['echeck'] = dom_tree.find('input', {'type': 'radio', 'value': 'echeck'})
# 3. Submit Payment
elements['submit_payment'] = dom_tree.find('button', {'type': 'submit'})
# 4. Click all invoices
elements['invoice_checkboxes'] = dom_tree.find_all('input', {'type': 'checkbox', 'name': 'invoice'})
# 5. Continue button
elements['continue_button'] = dom_tree.find('button', string=lambda text: text and 'continue' in text.lower())
# In ra kết quả
for key, el in elements.items():
if isinstance(el, list):
print(f"{key}: {[e.get('id') or e.get('name') or e.get('value') for e in el]}")
else:
print(f"{key}: {el.get('id')}")
🧠 Mở rộng – Nếu prompt thay đổi
Với logic parser này, nếu prompt là "Choose payment option as Credit Card and proceed" thì hệ thống chỉ cần:
dò "choose" hoặc "select" ⇒ là hành động click
nhận diện "credit card" là target text
tìm trong DOM các radio/select options có giá trị như "credit card"
Tất cả sẽ chạy tự động nếu bạn làm đúng giải pháp giống như đã trình bày ở phần trên với PromptProcessor, ElementFinder.
✅ TL;DR (Tóm tắt)
Bạn phân tích prompt thành actions → "click" / "select" / "submit" / "input" / "wait".
Ánh xạ chúng với DOM tree để tìm element tương ứng qua các đặc điểm như text, value, id, name...
Bạn có thể dùng BeautifulSoup hoặc Selenium để tìm những element này theo từng mục đích (click, điền dữ liệu).
Prompt có thể thay đổi, nhưng nếu phân tích ngữ nghĩa đúng, thì mapping vào DOM là rất linh hoạt.
Nếu bạn muốn, mình có thể cung cấp 1 script hoàn chỉnh từ prompt ➜ elements để bạn dùng thử. OK thì bạn bảo mình nhé!