python之selenium调用xpath实现网页操作
目录[*]源码
[*]过程中遇到的主要问题
[*]主要涉及的技术处理
源码
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").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").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").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/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")
listname("/html/body/table/tbody/tr/td/a")过程中遇到的主要问题
1.调用xpath之前 需要先调用frame 以定位!!!
2.定位到新的frame 需要先退出之前的frame
主要涉及的技术处理
1.xpath调用
2.浏览器驱动调用
3.网页弹框处理
4.传参调用函数
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]