- #_*_ coding:utf-8 _*_
- import time
- from selenium import webdriver
- from selenium.webdriver.common.action_chains import ActionChains
- from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
- DesiredCapabilities.INTERNETEXPLORER['ignoreProtectedModeSettings'] = True
- version = "1.03.0521.1113"
- versionname = u"基础包"
- versiondescription = u"基础包"
- iedriver = "C:\\Program Files\\Internet Explorer\\IEDriverServer.exe"
- update_main = webdriver.Ie(iedriver)
- #打开浏览器登录
- update_main.get("http://*******")
- update_main.find_element_by_id("username").send_keys("******")
- update_main.find_element_by_id("password").send_keys("******")
- update_main.find_element_by_class_name("reg").click()
- time.sleep(2)
- #点击leftframe升级版本列表
- update_main.switch_to_frame("leftFrame")
- update_main.find_element_by_xpath("//a[@target='main']").click()
- time.sleep(2)
- #新增升级版本
- update_main.switch_to_default_content()
- update_main.switch_to_frame("main")
- update_main.find_element_by_xpath("//input[@value='新增升级版本']").click()
- update_main.find_element_by_id("showInsertUpdateUpgradeMainVersion_upgradeMainVersionBean_version").send_keys(version)
- update_main.find_element_by_id("showInsertUpdateUpgradeMainVersion_upgradeMainVersionBean_name").send_keys(versionname)
- update_main.find_element_by_id("showInsertUpdateUpgradeMainVersion_upgradeMainVersionBean_description").send_keys(versiondescription)
- update_main.find_element_by_xpath("//input[@value='提交']").click()
- #打开新建立的版本
- update_main.switch_to_default_content()
- update_main.switch_to_frame("main")
- update_main.find_element_by_xpath("//div[@class='tablePanel marginTop']/form/table/tbody/tr[2]/td[1]/a[1]").click()
- update_main.find_element_by_xpath("//input[@value='新增放量']").click()
- #填写版本信息
- update_main.find_element_by_id("go_upgradeCtrlBean_name").send_keys(u"第一次放量")
- update_main.find_element_by_id("go_upgradeCtrlBean_maxUpgradeCount").send_keys("10")
- update_main.find_element_by_id("upgradeCtrlBean.includeOsArray-1").click()
- update_main.find_element_by_id("upgradeCtrlBean.includeOsArray-2").click()
- update_main.find_element_by_id("upgradeCtrlBean.includeOsArray-3").click()
- update_main.find_element_by_id("upgradeCtrlBean.upgradeModeArray-1").click()
- update_main.find_element_by_xpath("//input[@value='选择']").click()
- update_main.switch_to_frame("selectVersionIframe")
- update_main.maximize_window()
- update_main.find_element_by_xpath("//img[@src='images/page-tag-small/lastPage.gif']").click()
- update_main.find_element_by_id("5.01.1126.1111").click()
- update_main.find_element_by_xpath("//td[@valign='middle']/input").click() #选择版本后点击确定
- update_main.switch_to_default_content()
- update_main.switch_to_frame("main")
- update_main.find_element_by_id("go_upgradeConfigBean_showCount").send_keys("1")
- update_main.find_element_by_id("go_upgradeConfigBean_noticeModedefault").click()
- update_main.find_element_by_id("go_upgradeConfigBean_p2psettingsOpen0").click()
- update_main.find_element_by_id("go_upgradeConfigBean_autoUpdateInterval").find_element_by_xpath("//option[@value='24']").click()
- update_main.find_element_by_id("submitbtn").click()
- time.sleep(1)
- #升级设置
- update_main.find_element_by_xpath("//div[@class='tablePanel']/form/table/tbody/tr[2]/td[9]/a[1]").click()
- update_main.find_element_by_id("upgradeMode").find_element_by_xpath("//option[@value='0']").click()
- #上传文件
- fileObj = open('upload_list.txt','rb')
- uploadList = fileObj.readlines()
- fileObj.close()
- isFirst = True
- for fileName in uploadList:
- fileName = fileName.strip()
- if not isFirst:
- update_main.switch_to_default_content()
- update_main.switch_to_frame("main")
- else:
- isFirst = False
- update_main.find_element_by_id("uploadbtn").click()
- update_main.switch_to_frame("uploadFileFrame") #获取上传窗口焦点
- cmdLine = '''update_main.find_element_by_name("upload").send_keys("%s")''' % fileName
- print cmdLine
- exec cmdLine
- update_main.find_element_by_xpath("//input[@id='okButton']").click()
- update_main.find_element_by_id("cancelButton").click()
- #编辑xml
- update_main.switch_to_default_content()
- update_main.switch_to_frame("main")
- nowhandle = update_main.current_window_handle
- update_main.find_element_by_id("editbtn1").click() #在线编辑subsystem
- allhandles = update_main.window_handles #--------------
- f = open('file_path_info.txt','rb')
- filePathInfoList = f.readlines()
- f.close()
- for handle in allhandles:
- if handle != nowhandle:
- update_main.switch_to_window(handle)
- update_main.maximize_window()
- for i in range(1,44):
- subsystem = update_main.find_element_by_id("eName0") #subsystem节点
- ActionChains(update_main).context_click(subsystem).perform() #
- update_main.find_element_by_xpath("//td[@vAlign='middle']").click() #选择package
- update_main.find_element_by_xpath("//div[@id='showDivContent']/div[%s]" % i).click() #定位右侧滚动条
- js = "document.getElementById('showDivContent').scrollTop = %s;" %( i * 20)
- update_main.execute_script(js) #
- for filePath in filePathInfoList:
- fileName,pathName = filePath.strip().split(":")
- idName = update_main.find_element_by_xpath("//input[@value=%s]" % fileName).get_attribute("id")
- update_main.find_element_by_id(idName.replace("_Name","_Path")).send_keys(pathName.replace("'",""))
- update_main.find_element_by_xpath("//input[@value='保存修改']").click()
- #update_main.close()
- #update_main.switch_to_window(nowhandle)
- #该片段来自于http://www.codesnippet.cn/detail/0408201410118.html
来源: http://www.codesnippet.cn/detail/0408201410118.html