def submit(self): # Это всё для Chrome actions = Actions(self.driver) WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( lambda d: d.find_element_by_xpath(self.CREATE_BUTTON).is_enabled()) create_button = self.driver.find_element_by_xpath(self.CREATE_BUTTON) actions.execute_script('window.scrollTo(0, {});'.format( create_button.location['y'])) actions.wait_and_click(By.XPATH, self.CREATE_BUTTON)
def insert_image(self, url, align='', description='', as_link=False): actions = Actions(self.driver) actions.wait_and_click(By.XPATH, self.ADD_IMAGE) WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( expected_conditions.presence_of_element_located( (By.XPATH, self.WINDOW_UPLOAD))) actions.wait_and_click(By.XPATH, self.FROM_INTERNET) actions.clear(By.XPATH, self.INPUT_IMG_URL) actions.send_keys_to_elem_and_perform(By.XPATH, self.INPUT_IMG_URL, url) align_selector = Select( self.driver.find_element_by_xpath(self.ALIGN_SELECT_FROM_INTERNET)) align_selector.select_by_value(align) actions.wait_and_click(By.XPATH, self.IMAGE_DESCRIPTION_FROM_INTERNET) actions.send_keys_and_perform(*description) if as_link: actions.wait_and_click( By.XPATH, self.SUBMIT_INSERT_IMAGE_AS_LINK_FROM_INTERNET) else: actions.wait_and_click(By.XPATH, self.SUBMIT_UPLOAD_IMAGE_FROM_INTERNET) WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( lambda d: description in d.find_element_by_xpath( self.MAIN_TEXT).get_attribute('value'))
def upload_image(self, path_to_file, align='', description=''): actions = Actions(self.driver) actions.wait_and_click(By.XPATH, self.ADD_IMAGE) WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( expected_conditions.presence_of_element_located( (By.XPATH, self.WINDOW_UPLOAD))) actions.wait_and_click(By.XPATH, self.FROM_PC) actions.send_keys_to_elem_and_perform(By.XPATH, self.INPUT_IMG_FILE, path_to_file) align_selector = Select( self.driver.find_element_by_xpath(self.ALIGN_SELECT_FROM_PC)) align_selector.select_by_value(align) actions.wait_and_click(By.XPATH, self.IMAGE_DESCRIPTION_FROM_PC) actions.send_keys_and_perform(*description) actions.wait_and_click(By.XPATH, self.SUBMIT_IMAGE_FILE) WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( lambda d: description in d.find_element_by_xpath( self.MAIN_TEXT).get_attribute('value'))
def add_user(self, name): actions = Actions(self.driver) actions.wait_and_click(By.XPATH, self.ADD_USER) actions.wait_and_click(By.XPATH, self.SEARCH_USER_POPUP) actions.send_keys_and_perform(name) actions.submit(By.XPATH, self.SEARCH_USER_POPUP) choose_user = '******' + name + '")]' WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( expected_conditions.presence_of_element_located( (By.XPATH, choose_user))) actions.wait_and_click(By.XPATH, choose_user) WebDriverWait(self.driver, conf.TIMEOUT, conf.POLL_FREQUENCY).until( lambda d: name in d.find_element_by_xpath(self.MAIN_TEXT ).get_attribute('value'))
def add_link_to_main_text(self, url, name): actions = Actions(self.driver) actions.wait_and_click(By.XPATH, self.ADD_LINK) actions.wait_alert() actions.set_text_to_alert(url) actions.send_keys_and_perform(name)