def try_click_add(driver): attemtp = 0 res = False while attemtp < 5: try: wait_xpath(driver, add_btn_xpath).click() res = True print('worked!!!!!!!!!!!!!!!!!!!!!!') break except StaleElementReferenceException: print('Exeption Occurred!!!!!!!!!!!!!!!!!') attemtp += 1 return res
def add_one_object(driver, object_line): while 1: add_ok = try_click_add(driver) if add_ok: break save = wait_xpath(driver, save_btn_xpath) fill_objects_details(driver, object_line[0], object_line[1], object_line[2]) save.click() edit = wait_xpath(driver, edit_btn_xpath) while not (edit.is_displayed() and edit.is_enabled): print('waiting...for Edit button') wait_xpath(driver, back_btn_xpath).click()
def add_targets_to_object(obj_name, priority, ttName, Desc, driver): global current_obj if current_obj == obj_name: time.sleep(1) fill_target_details(priority, ttName, Desc, driver) else: # wait_xpath(driver, '//*[@id="Cancel"]/div/span').click() time.sleep(2) current_obj = obj_name # if has_targets(driver): driver.back() wait_xpath(driver, build_xpath_targets_btn(current_obj)).click() time.sleep(1) fill_target_details(priority, ttName, Desc, driver)
def has_targets(driver): global save_btn try: save_btn = wait_xpath(driver, '//*[@id="Save"]/div/span') return True except: return False
driver.implicitly_wait(50) user = driver.find_element_by_id('username') pw = driver.find_element_by_id('passwd') login_btn = driver.find_element_by_id('login-button') user.send_keys('administrator') pw.send_keys('Br3wst3r') login_btn.click() util.navigate_to_migrate(driver) ro.navigate_to_add_page(driver) with open('objects.csv', 'r') as f: print('Starting Adding Objects######################') lines = csv.reader(f, delimiter='\t') for line in lines: time.sleep(0.5) ro.add_one_object(driver, line) print('Finishing Adding Obejcts#####################') time.sleep(1) util.wait_xpath(driver, '//*[@id="loadSiteBar"]/div/span[1]').click() util.navigate_to_migrate(driver) util.select_pa(driver, 'PTP') with open('objects.csv', 'r') as f: lines = csv.reader(f, delimiter='\t') for line in lines: pa.start_add(driver, line) driver.close()
def navigate_to_add_page(driver): wait_xpath(driver, elements_xpath).click() wait_xpath(driver, objects_xpath).click()
def fill_target_details(priority, ttName, Desc, driver): wait_xpath(driver, priority_input_xpath).send_keys(priority) wait_xpath(driver, ttName_input_xpath).send_keys(ttName) wait_xpath(driver, desc_input_xpath).send_keys(Desc) wait_xpath(driver, '//*[@id="Save"]/div/span').click()
def add_object_pa(driver, line_object): print('***processing => ', line_object) try_click_add(driver) wait_xpath(driver, '//*[text()="[Choose one]"]').click() obj = '{} - {}'.format(line_object[0], line_object[1]) print('inserting obj is: ', obj) obj_list = driver.find_elements_by_xpath('//span[@class="select2-match"]/parent::div') for o in obj_list: if o.text == obj: print('clicking...') o.click() print('clicked....!') break # wait_xpath(driver, '//*[@id="select2-drop"]/div[1]/input').send_keys(obj) # object_element = wait_xpath(driver, '//ul//div[@class="select2-result-label"]/span') # ActionChains(driver).move_to_element(object_element).click().perform() priority_element = wait_xpath(driver, '/html/body/div[1]/div[2]/div[3]/div/div[3]/div[2]/div[2]/div/div[2]/table/tbody/tr[1]/td[5]/input') priority_element.send_keys(line_object[0]) comment_element = wait_xpath(driver, '/html/body/div[1]/div[2]/div[3]/div/div[3]/div[2]/div[2]/div/div[2]/table/tbody/tr[2]/td/input') comment_element.send_keys(line_object[2]) time.sleep(0.5) wait_xpath(driver, '//*[@id="Save"]/div/span').click() data_source_id = wait_xpath(driver, data_source_id_xpath).text print(data_source_id) wait_xpath(driver, '//*[text()="[Choose one]"]').click() insert_box = wait_xpath(driver, '//*[@id="select2-drop"]/div[1]/input') time.sleep(0.5) ActionChains(driver).move_to_element(insert_box).send_keys(data_source_id).send_keys(Keys.ENTER).perform() wait_xpath(driver, '/html/body/div[1]/div[2]/div[4]/div/div[1]/div[2]/div[1]/div').click()