源码
|
from selenium import webdriver |
|
#import pyautogui |
|
from time import sleep |
|
from selenium.webdriver.common.by import By |
|
from selenium.webdriver.chrome.service import Service |
|
|
|
s = Service("msedgedriver.exe") |
|
driver = webdriver.Edge(service=s) |
|
driver.get('http://192.168.28.101/WebLog/index.jsp?userName=jianghj') #打开网页 |
|
driver.maximize_window() #最大化窗口 |
|
#进入填写当前日志frame |
|
driver.switch_to.frame("leftFrame") |
|
driver.find_element(by=By.XPATH, value="/html/body/a[1]").click() |
|
sleep(1) |
|
driver.switch_to.default_content() #切换回主frame 以进入列表frame进行填写 |
|
driver.switch_to.frame("mainFrame") #列表和进入列表的frame都是mainFrame |
|
|
|
def commit(): #提交 |
|
driver.find_element(by=By.XPATH, value="/html/body/form/p/input[1]").click() #提交按钮 |
|
#sleep(1) |
|
#处理网页弹框 |
|
alert=driver.switch_to.alert |
|
print(alert.text) |
|
alert.accept() |
|
alert.accept() |
|
def review(): #复核 |
|
driver.find_element(by=By.XPATH, value="/html/body/form/p/input[2]").click() #复核按钮 |
|
#sleep(1) |
|
#处理网页弹框 |
|
alert=driver.switch_to.alert |
|
print(alert.text) |
|
alert.accept() |
|
alert.accept() |
|
sleep(1) |
|
def listname(listname): #进入表格 |
|
driver.find_element(by=By.XPATH, value=listname).click() #进入表格 也是mainframe |
|
commit() #提交 |
|
#复核 |
|
driver.find_element(by=By.XPATH, value=listname).click() |
|
#sleep(1) |
|
review() #复核 |
|
|
|
listname("/html/body/table/tbody/tr[2]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[3]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[4]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[5]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[6]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[7]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[8]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[9]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[10]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[11]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[12]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[13]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[14]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[15]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[16]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[17]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[18]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[19]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[20]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[21]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[28]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[30]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[31]/td[2]/a") |
|
listname("/html/body/table/tbody/tr[32]/td[2]/a") |
过程中遇到的主要问题
1.调用xpath之前 需要先调用frame 以定位!!! 2.定位到新的frame 需要先退出之前的frame
主要涉及的技术处理
1.xpath调用 2.浏览器驱动调用 3.网页弹框处理 4.传参调用函数