# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# @Name: login
# @Description:
# @Author: springbocai
# @Date: 2019/5/22
#-------------------------------------------------------------------------------
from selenium import webdriver
import time
import random
driver = webdriver.Chrome()
driver.implicitly_wait(20) # 隐性等待,最长等30秒
driver.get('http://#######')
driver.find_element_by_id('username').send_keys('##')
driver.find_element_by_id('userpass').send_keys('##')
driver.find_element_by_id('loginBtn').click()
# 进入系统选择页面
driver.find_element_by_css_selector('#sysSelect > div.column.column2 > a:nth-child(3) > i').click()
time.sleep(1)
driver.find_element_by_class_name('dropdown-toggle').click()
driver.find_element_by_link_text('数据维护系统').click()
'''
这个是通过查询这个列表,然后在列表当中再去匹配
for i in driver.find_elements_by_xpath('/html/body/div/div[1]/div/div/div/ul/li[1]/ul/li'):
if i.get_attribute('textContent')=='数据维护系统':
i.click()
else:
print('该用户无数据维护系统权限')
driver.quit()
'''
#断言
driver.find_elements_by_xpath('//*[@id="organizationsPage"]/div/div[2]/div/div[1]/h3')
print('当前在机构管理页面')
#添加二级机构
driver.find_element_by_id('tree_view_defaut_1_span').click() #选择根节点
driver.find_element_by_id('addButton').click()
# 弹出页面添加
jgmc_sz = random.randrange(1,100)
jgmc_qz = '2级部门'
jgmc2 = jgmc_qz+ str(jgmc_sz)
print(jgmc2)
# 添加2级部门
driver.find_element_by_id('add1_name').send_keys(jgmc2)
driver.find_element_by_xpath('//*[@id="addModal"]/div[2]/div[2]/div[2]/label[1]/input').click()
driver.find_element_by_xpath('//*[@id="addModal"]/div[2]/div[2]/div[2]/label[5]/input').click()
driver.find_element_by_id('addModalButton').click() #保存
driver.refresh()
time.sleep(2)
for i in driver.find_elements_by_xpath('//*[@id="tree_view_defaut_1_ul"]/li'):
print(i.text)
if i.text == jgmc2:
time.sleep(2)
i.click()
two_tree2=i.get_attribute('id')+'_switch' #拿到添加当前2级部门的ID 属性 拼接一个 _switch,为了后面打开树节点
print(two_tree2)
jgmc_sz = random.randrange(1, 100)
jgmc_qz = '3级部门'
jgmc3 = jgmc_qz + str(jgmc_sz)
print(jgmc3)
# 添加3级部门
driver.find_element_by_id('addButton').click()
driver.find_element_by_id('add1_name').send_keys(jgmc3)
driver.find_element_by_xpath('//*[@id="addModal"]/div[2]/div[2]/div[2]/label[1]/input').click()
driver.find_element_by_xpath('//*[@id="addModal"]/div[2]/div[2]/div[2]/label[5]/input').click()
driver.find_element_by_id('addModalButton').click() #保存
driver.refresh()
time.sleep(2)
print('##########################')
driver.refresh()
time.sleep(2)
print(two_tree2)
# 展开2级节点
time.sleep(2)
# driver.find_element_by_xpath('//*[@id="%s"]'% two_tree2).click()
driver.find_element_by_xpath('//*[@id="{}"]'.format(two_tree2)).click() # 点开之前新增的2级节点
time.sleep(2)
# 点击三级节点
driver.find_element_by_xpath('//*[@id="tree_view_defaut_1_ul"]/li/ul/li/a/span[text()="{}"] '.format(jgmc3)).click()
jgmc_sz = random.randrange(1, 100)
jgmc_qz = '4级部门'
jgmc4 = jgmc_qz + str(jgmc_sz)
print(jgmc4)
# 添加4级部门
driver.find_element_by_id('addButton').click()
driver.find_element_by_id('add1_name').send_keys(jgmc3)
driver.find_element_by_xpath('//*[@id="addModal"]/div[2]/div[2]/div[2]/label[1]/input').click()
driver.find_element_by_xpath('//*[@id="addModal"]/div[2]/div[2]/div[2]/label[5]/input').click()
driver.find_element_by_id('addModalButton').click() #保存
time.sleep(2)