selenium综合脚本调试

登录 - 新建学校 - 禁用学校 - 设置时间

涉及到的重点知识点:
1.xpath定位(父级定位)
2.iframe 切换

import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://120.25.209.187:8080/recruit.students/login/view')
driver.maximize_window() # 浏览器最大化
#登录
driver.find_element_by_id('txtUserName').send_keys("admin")
time.sleep(3)
driver.find_element_by_id('txtPassword').send_keys("test123")
time.sleep(3)
driver.find_element_by_xpath('//*[@id="loginForm"]/a').click()
time.sleep(3)
#新建学校
# driver.find_element_by_xpath("//button[text()='新建']").click()
# time.sleep(3)
# driver.find_element_by_id("schoolName_add").send_keys("test123")
# time.sleep(1)
# driver.find_element_by_id("add_schoolType1").click()
# time.sleep(1)
# driver.find_element_by_id("canRecruit_add").click()
# time.sleep(1)
# driver.find_element_by_id("remark_add").send_keys("wu")
# time.sleep(1)
# driver.find_element_by_id("addSchoolSubmit").click()
# time.sleep(1)
driver.find_element_by_xpath('//*[@id="Checkbox1"]').click()
time.sleep(1)#勾选要设置的学校
driver.find_element_by_xpath('//*[@id="sour"]/div[4]/button[3]').click()
time.sleep(1)#点击设置时间
driver.find_element_by_xpath('//*[@id="startTime"]').click()
time.sleep(1)#点击第一个框
driver.switch_to.frame(driver.find_element_by_xpath('//*[@id="_my97DP"]/iframe'))#加载iframe
driver.find_element_by_xpath('/html/body/div/div[3]/table/tbody/tr[2]/td[5]').click()#点击时间
driver.switch_to.default_content()#退出iframe
time.sleep(1)

driver.find_element_by_xpath('//*[@id="endTime"]').click()#点击第二个输入框
time.sleep(1)
driver.switch_to.frame(driver.find_element_by_xpath('//*[@id="_my97DP"]/iframe'))#加载frame
driver.find_element_by_xpath('/html/body/div/div[3]/table/tbody/tr[4]/td[4]').click()#选择时间
driver.switch_to.default_content()#退出frame
time.sleep(1)
driver.find_element_by_xpath('//*[@id="setEnrollmentTime"]').click()#点击确定


shop项目

from selenium import webdriver
from time import sleep

driver = webdriver.Chrome()
driver.get('http://192.168.174.128/xiaoqiangshop/user.php')
driver.maximize_window()

sleep(2)
driver.find_element_by_name('username').send_keys('xiaoqiang1')
driver.find_element_by_name('password').send_keys('123123')
driver.find_element_by_name('submit').click()

sleep(3)
driver.get('http://192.168.174.128/xiaoqiangshop/goods.php?id=136')
sleep(3)
driver.find_element_by_xpath("//a[text()='加入购物车']").click()
sleep(2)
driver.find_element_by_xpath('/html/body/div[5]/div[1]/table/tbody/tr/td[2]/a/img').click()
sleep(2)

# 滚动条底部
js = "window.scrollTo(0,document.body.scrollHeight)"
driver.execute_script(js)
sleep(2)
# //*[@id="ECS_FORMBUY"]/ul[3]/li[2]/a
# /html/body/div[5]/div[1]/table/tbody/tr/td[2]/a/img
# //*[@id="theForm"]/div[11]/div[2]/input[1]
# driver.find_element_by_xpath("//div[@id='ECS_ORDERTOTAL']/..div[2]/input[1]").click()
driver.find_element_by_xpath('//*[@id="theForm"]/div[11]/div[2]/input[1]').click()

posted @ 2022-08-13 14:30  西瓜_皮  阅读(169)  评论(0编辑  收藏  举报