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 list_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.LIST)
def get_text(self): return Actions(self.driver).wait_and_get_text(By.XPATH, self.TEXT)
def add_poll(self, question, *answers): actions = Actions(self.driver) actions.click_to_element(By.XPATH, self.ADD_POLL_CHECKBOX) actions.send_keys_to_elem_and_perform(By.XPATH, self.QUESTION_POLL, question) count = len(answers) for index in range(count): answer_xpath = self.ANSWEAR_POLL.format(index) if not actions.element_is_exist(By.XPATH, answer_xpath): answer_xpath += '[2]' actions.click_and_wait(By.XPATH, self.ADD_OPTION_ANSWER, By.XPATH, answer_xpath) actions.send_keys_to_elem_and_perform(By.XPATH, answer_xpath, answers[index])
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 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)
def forbid_comment_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.FORBID_COMMENT)
def add_additional_answer_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.ADD_OPTION_ANSWER)
def h6_text_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.H6_BUTTON)
def get_poll_answers(self): actions = Actions(self.driver) elements = actions.get_list_elements(By.XPATH, self.POLL_ANSWER) return actions.get_list_text_from_list_elements(*elements)
def has_add_comment_btn(self): return Actions(self.driver).element_is_exist(By.XPATH, self.ADD_COMMENT)
def get_inner_html_text(self): return Actions(self.driver).wait_and_get_attribute( By.XPATH, self.TEXT, 'innerHTML')
def delete(self): actions = Actions(self.driver) actions.click_to_element(By.XPATH, self.DELETE_BUTTON) actions.click_to_element(By.XPATH, self.DELETE_BUTTON_CONFIRM)
def open_blog(self): Actions(self.driver).click_to_element(By.XPATH, self.BLOG)
def numbered_list_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.NUMBERED_LIST)
def bold_text_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.BOLD_TEXT)
def add_poll_checkbox_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.ADD_POLL_CHECKBOX)
def italic_text_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.ITALIC_TEXT)
def delete_additional_answer_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.DELETE_OPTION_ANSWER)
def strikethrough_text_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.STRIKETHROUGH_TEXT)
def select_main_text(self): Actions(self.driver).select_text(By.XPATH, self.MAIN_TEXT)
def underline_text_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.UNDERLINE_TEXT)
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 quote_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.QUOTE)
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 code_click(self): Actions(self.driver).wait_and_click(By.XPATH, self.CODE)
def get_info(self): return Actions(self.driver).wait_and_get_text(By.XPATH, self.INFO_BLOCK)
def get_title(self): return Actions(self.driver).wait_and_get_text(By.XPATH, self.TITLE)