def copy_to_templet(driver, vmName): # result=select_vm(driver,vmName) isstop_vm(driver, vmName) # vmName2=result[0] templa_name = templaname_gen() driver.find_element_by_xpath( "//*[@id='operations']/a/span[contains(text(),'复制为模板')]").click() # WebDriverWait(driver, 20).until( # EC.element_to_be_clickable((By.XPATH, u"//*[@id='copy_as_template_form']/div/div/input[@name='name']"))).send_ke # driver.find_element_by_xpath(u"//*[@id='copy_as_template_form']/div/div/input[@name='name']").clear() driver.find_element_by_xpath( u"//*[@id='copy_as_template_form']/div/div/input[@name='name']" ).send_keys(templa_name) driver.find_element_by_xpath( u"//*[@id='copy_as_template_form']/div/div/textarea").send_keys( templa_name) driver.find_element_by_xpath(u"//*[@id='submit_but']").click() info = WebDriverWait(driver, 20).until( EC.visibility_of_element_located( (By.XPATH, u"//*[@id='infoMessage']"))).text WebDriverWait(driver, 20).until( EC.element_to_be_clickable( (By.XPATH, u"html/body//div[contains(@style,'display: block;')]/div/button" ))).click() if info.__contains__("复制为模板任务启动成功!"): print("复制为模板任务启动成功") else: print("复制为模板任务启动failed")
def copy_to_templet(driver, vmName): # # result=select_vm(driver,vmName) # isstop_vm(driver, vmName) # # # vmName=result[0] # templa_name = templaname_gen() # self.select_vm(driver, vmName) WebDriverWait(driver, 30).until( EC.element_to_be_clickable(( By.XPATH, u'//*[@id="mCSB_1_container"]/ul[1]/li/a/span[contains(text(),"虚拟机管理")]' ))).click() time.sleep(10) WebDriverWait(driver, 30).until( EC.element_to_be_clickable(( By.XPATH, "//*[@id='stretch-table']/tbody/tr[@displayname='%s']/td[1]/input" % vmName))).click() templa_name = "testqa" + time.strftime("%H%M%S") time.sleep(5) driver.find_element_by_xpath( "//*[@id='operations']/a/span[contains(text(),'复制为模板')]").click() driver.find_element_by_xpath( "//*[@id='copy_as_template_form']/div/div/input[@name='name']" ).send_keys(templa_name) driver.find_element_by_xpath( "//*[@id='copy_as_template_form']/div/div/textarea").send_keys( templa_name) time.sleep(3) driver.find_element_by_xpath("//*[@id='submit_but']").click() info = WebDriverWait(driver, 20).until( EC.visibility_of_element_located( (By.XPATH, u"//*[@id='infoMessage']"))).text WebDriverWait(driver, 20).until( EC.element_to_be_clickable(( By.XPATH, u"html/body//div[contains(@style,'display: block;')]/div/button" ))).click() if info.__contains__("复制为模板任务启动成功!"): print("复制为模板任务启动成功") else: print("复制为模板任务启动failed")