|
# 新增表单工程
# -*- coding:utf-8 -*-
from selenium import webdriver
import time
import os
driver = webdriver.Firefox()
driver.get('http://192.168.3.30:8686/actModer/login.jsp')
elem_user = driver.find_element_by_id('user_name')
elem_user.clear
elem_user.send_keys('admin')
elem_pwd = driver.find_element_by_id('user_pwd')
elem_pwd.clear
elem_pwd.send_keys('123456')
driver.find_element_by_id('bpm_login').click()
time.sleep(3)
# 用xpath定位元素,如果路径过长会报错,前面加等待时间
# 定位“表单编辑”并打开表单列表
driver.find_element_by_xpath('/html/body/div[1]/div/ul/li[2]/a').click() # 通过xpath定位元素
# driver.find_element_by_link_text('表单编辑').click() #通过link_text定位元素
time.sleep(2)
# 新增表单
driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/a[1]/span/span[1]').click()
time.sleep(5)
# 切换窗口
all_handles = driver.window_handles
# print(all_handles)
now_handle = driver.current_window_handle
# print('now_handle:',now_handle)
for handle in all_handles:
if handle != now_handle:
# print('handle:',handle)
driver.switch_to_window(handle)
# print(now_handle)
break
driver.switch_to_window(handle)
# print('now',handle)
time.sleep(3)
# 定位元素新建工程和页面
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[1]/div[1]/div/div[1]/button/span').click()
driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[1]/div[1]/div/div[2]/button/span').click()
# 引入ActionChains类
from selenium.webdriver.common.action_chains import ActionChains
# 修改工程名称
time.sleep(2)
left_click = driver.find_element_by_id('treeDemo_1_a')#选定要修改的工程
ActionChains(driver).click_and_hold(left_click).perform()
time.sleep(2)
modify = driver.find_element_by_id('treeDemo_1_edit')#选择修改按钮元素
ActionChains(driver).double_click(modify).perform()
driver.switch_to_alert().accept()#进入编辑状态
editing_project = driver.find_element_by_id('treeDemo_1_span')
editing_project.send_keys('123')
#鼠标点击空白处 退出编辑
time.sleep(2)
left_click_1 = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[1]/div[2]')
ActionChains(driver).click_and_hold(left_click_1).perform()
#双击并打开页面
time.sleep(1)
double_click = driver.find_element_by_id('treeDemo_2_span')
ActionChains(driver).double_click(double_click).perform()
time.sleep(10)
#driver.quit()
|
|