#coding=utf-8
'''
添加UEGroup,app,OS
'''
from selenium import webdriver
import time
import sys
import datetime
import user_def
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
#程序执行起始时间
#starttime = time.clock()
starttime = datetime.datetime.now()
#firefox
profile = webdriver.FirefoxProfile(user_def.browserpath)
browser = webdriver.Firefox(profile)
print '浏览器最大化'
browser.maximize_window()
time.sleep(1)
#print 'set browser width:700 and height:800'
#browser.set_window_size(700,800)
firsturl='http://10.157.0.31/webwxw/htdocs/'
print "now access %s" %(firsturl)
browser.get(firsturl)
print browser.title
#click Append
browser.find_element_by_xpath("//*[@id='tbUEgroup']/a[1]").click()
#input UEGroup name (fix15)
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[1]/div/table/tbody/tr/td/input").send_keys(user_def.UEGroup_Name)
#input BaseCallNumber (fix15)
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[2]/div/table/tbody/tr/td/input").send_keys(user_def.BaseCallNumber)
#choose Type-展开下拉项 (fix15)
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[3]/div/table/tbody/tr/td/span/span/a").click()
#定位这个下拉框,稍微有点棘手,有id但无法定位,就用xpath一级一级定位和原始xpath试试,再或者用css path试试
#一级一级的定位还是比较靠谱,有时候比原始xpath还靠谱
#选中正确的type
xpath = "//*[@id='wrapUEgroup']/div[4]/div/div[" + str(i) + "]"
browser.find_element_by_xpath(xpath).click()
#input BaseValue (fix15)
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[4]/div/table/tbody/tr/td/input").send_keys(Keys.CONTROL,'a')
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[4]/div/table/tbody/tr/td/input").send_keys(Keys.BACK_SPACE)
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[4]/div/table/tbody/tr/td/input").send_keys(user_def.BaseValue)
#input NoOfUEs (fix15)
browser.find_element_by_xpath("//*[@id='datagrid-row-r1-2-0']/td[5]/div/table/tbody/tr/td/span/input[1]").send_keys(user_def.NoOfUEs)
#click Save
browser.find_element_by_xpath("//*[@id='tbUEgroup']/a[5]").click()
#跳出当前frame
browser.switch_to_default_content()
print "Add UEGroup OK !"
print ""
#open Configuration page
browser.find_element_by_link_text("Configuration").click()
#必须先切到外层frame,才能继续切入内层frame
browser.switch_to_frame("Configuration")
print "Setup Configuration..."
##############ADD UEGroup################
print "Adding UEGroup……"
#技术点:列表
li = [1,2,3]
types = ['TMSI','IMSI','UEIP']
i = li[types.index(user_def.group_Type)]
#遇到没有id、name的frame,那就先定位frame的位置,然后再切换到该位置上
gpframe = browser.find_element_by_xpath("//*[@id='configCon']/div[2]/div/div/iframe")
browser.switch_to_frame(gpframe)