from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import pyautogui as ui
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://demo-shop.winrobot360.com/user/login?redirect=%2Flist%2Ftable-list')
driver.implicitly_wait(5)
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import pyautogui as ui
#初始化webdriver
driver = webdriver.Chrome()
#窗口最大化
driver.maximize_window()
#初始化一个网页
driver.get('https://demo-shop.winrobot360.com/user/login?redirect=%2Flist%2Ftable-list')
#隐式等待
driver.implicitly_wait(5)
#定位元素,找到用户名输入框
user_name = driver.find_element(By.ID, 'username')
#输入admin
user_name.send_keys('admin')
#定位元素,找到密码输入框
pwd = driver.find_element(By.ID, 'password')
pwd.send_keys('admin')
#定位登录按钮
login = driver.find_element(By.XPATH, '//*[@id="formLogin"]/div[3]/div/div/span/button')
#点击登录
login.click()
#页面发生跳转,进入一个新的页面
time.sleep(1)
#点击订单
menu = driver.find_element(By.XPATH, "/html/body/div[1]/section/aside/div/ul/li[3]/a")
menu.click()
time.sleep(2)
#找到存放页数的ul,找到总页数page_sum
ul = driver.find_element(By.XPATH, '//*[@id="app"]/section/section/main/div/div/div/div[2]/div/div/div/div[3]/div/div/ul')
ul_elements = ul.find_elements(By.TAG_NAME,'li')
page = ul_elements[-3]
page_sum = page.text
print(page)
for i in range(int(page_sum)):
print(i)
#每一页开始操作之前把滚动条置于最上方
js = "var q=document.documentElement.scrollTop=0"
driver.execute_script(js)
time.sleep(2)
trs = driver.find_elements(By.CLASS_NAME,"ant-table-row.ant-table-row-level-0")
print(trs)
for tr in trs:
tds = tr.find_elements(By.TAG_NAME,'td')
print(tds)
if tds[-2].text == '完成':
#点击完成
tds[-1].click()
#等待一下确认按钮,点击确定
time.sleep(0.5)
driver.find_element(By.CLASS_NAME,'ant-btn.ant-btn-primary.ant-btn-sm').click()
#按下箭头
ui.press('down')
ui.press('down')
#点击下一页
ul_elements[-2].click()
文章知识点与官方知识档案匹配,可进一步学习相关知识
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |