78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""诊断:登录 → 起草页 → 点模板,打印点击前后 URL 和页面文本。"""
|
|
import os, sys, time
|
|
|
|
BASE = os.path.dirname(os.path.abspath(__file__))
|
|
PARENT = os.path.dirname(BASE)
|
|
if PARENT not in sys.path:
|
|
sys.path.insert(0, PARENT)
|
|
|
|
from rpa_yisaiqi.apa_browser_adapter import ApaBrowserAdapter
|
|
|
|
DRAFT = ("http://contract-test.gzmpc.com:8080/km/agreement/km_agreement_apply/draft/"
|
|
"draft.jsp?isSimpleCategory=false"
|
|
"&mainModelName=com.landray.kmss.km.agreement.model.KmAgreementApply"
|
|
"&modelName=com.landray.kmss.km.agreement.model.KmAgreementTmpl")
|
|
|
|
a = ApaBrowserAdapter("http://contract-test.gzmpc.com:8080/")
|
|
a.open_url("http://contract-test.gzmpc.com:8080/")
|
|
time.sleep(2)
|
|
|
|
# 登录
|
|
a.fill_first(['input[name="j_username"]'], "test002")
|
|
a.fill_first(['input[name="j_password"]'], "1")
|
|
a.click_first(['a[class*="login_button"]'])
|
|
time.sleep(2)
|
|
print("登录后 URL:", a._driver.current_url)
|
|
|
|
# 进起草页
|
|
a.open_url(DRAFT)
|
|
time.sleep(3)
|
|
print("起草页 URL:", a._driver.current_url)
|
|
print("起草页是否有 最近使用模板:", "最近使用模板" in a._driver.find_element("tag name", "body").text)
|
|
|
|
# 找模板元素
|
|
try:
|
|
from selenium.webdriver.common.by import By
|
|
el = a._driver.find_element(By.XPATH, '//p[contains(@class,"title")][contains(@title,"非格式-采购协议")]')
|
|
print("找到模板元素:", el.get_attribute("title"))
|
|
print("元素可见:", el.is_displayed(), "位置:", el.location, "大小:", el.size)
|
|
|
|
# 尝试原生 click
|
|
print("尝试原生 click ...")
|
|
el.click()
|
|
time.sleep(3)
|
|
print("原生 click 后 URL:", a._driver.current_url)
|
|
print("body 含 客户编码:", "客户编码" in a._driver.find_element("tag name", "body").text)
|
|
except Exception as e:
|
|
print("错误:", e)
|
|
|
|
# 尝试 JS click
|
|
print("尝试 JS click ...")
|
|
try:
|
|
a._driver.execute_script("arguments[0].click()", el)
|
|
time.sleep(3)
|
|
print("JS click 后 URL:", a._driver.current_url)
|
|
print("body 含 客户编码:", "客户编码" in a._driver.find_element("tag name", "body").text)
|
|
except Exception as e:
|
|
print("JS click 错误:", e)
|
|
|
|
# 尝试 mousedown/mouseup/click 完整事件链
|
|
print("尝试完整事件链 click ...")
|
|
try:
|
|
a._driver.execute_script("""
|
|
var el = arguments[0];
|
|
var rect = el.getBoundingClientRect();
|
|
var cx = rect.left + rect.width/2, cy = rect.top + rect.height/2;
|
|
['mousedown','mouseup','click'].forEach(function(type){
|
|
el.dispatchEvent(new MouseEvent(type, {bubbles:true, cancelable:true, clientX:cx, clientY:cy}));
|
|
});
|
|
""", el)
|
|
time.sleep(3)
|
|
print("事件链 click 后 URL:", a._driver.current_url)
|
|
print("body 含 客户编码:", "客户编码" in a._driver.find_element("tag name", "body").text)
|
|
except Exception as e:
|
|
print("事件链 click 错误:", e)
|
|
|
|
print("DONE")
|