项目场景:
记录一下去年第一次使用selenium+pycharm实现自动化功能测试,比较简单
代码:
以某个网站为例
lqiyi.py文件如下
from threading import Thread
from selenium import webdriver
import time
from setting import PASSWORD
# 实例化出一个谷歌浏览器
driver = webdriver.Chrome()
driver.get('https://login.sui.com/')
driver.find_element_by_class_name('selectLoginTitle').click()
time.sleep(1)
driver.find_element_by_id('email').send_keys(PHONE)
time.sleep(1)
driver.find_element_by_id('pwd').send_keys(PASSWORD)
time.sleep(1)
driver.find_element_by_link_text('登录').click()
time.sleep(1)
driver.find_element_by_link_text('记一笔').click()
time.sleep(1)
#支出
#分类
driver.find_element_by_xpath("//*[@id='tb-category-1_text']").click()
time.sleep(1)
driver.find_element_by_xpath("//*[@id='ls-li-payout-5747294151']").click()
time.sleep(1)
driver.find_element_by_xpath("//*[@id='ls-li-payout-5747294153']").click()
time.sleep(1)
#账户
driver.find_element_by_xpath("//*[@id='tb-outAccount-1_text']").click()
time.sleep(1)
driver.find_element_by_xpath("//*[@id='tb-outAccount-1_v_546739730']").click()
time.sleep(1)
#金额
driver.find_element_by_xpath("//*[@id='tb-outMoney-1']").send_keys('12')
time.sleep(1)
#保存
driver.find_element_by_id('tb-save').click()
time.sleep(1)
#收入
driver.find_element_by_link_text('收入').click()
#批量管理
driver.find_element_by_xpath("//*[@id='fb-ctrlall']/span").click()
time.sleep(1)
driver.find_element_by_xpath("//*[@id='openall']").click()
time.sleep(1)
#转账
driver.find_element_by_link_text('转账').click()
time.sleep(1)
#收支趋势图
driver.find_element_by_xpath("//*[@id='divBox']/div[1]/ul/li[2]/a").click()
time.sleep(3)
#time.sleep(5)
#driver.quit()
setting.py 写上自己的电话和密码就好
PHONE='12345678901'
PASSWORD='12345678'