How to use web_elements method in toolium

Best Python code snippet using toolium_python

main.py

Source:main.py Github

copy

Full Screen

1from selenium import webdriver2from send_telegram import send_photo_Waiting, send_photo_Acceptance3from delete_png import remove_png4from wait_functions import wait_of_element, clickable5from selenium.webdriver.common.desired_capabilities import DesiredCapabilities6import autologin7import time8import pytest9import params10import web_elements11import bot_config12#Время задержки13delay = 1014#-----------------------------------------------------------------------------------------------------15# Вынесем инициализцию драйвера в отдельную фикстуру pytest16@pytest.fixture17def driver_init():18 options = webdriver.ChromeOptions()19 # options.add_argument('user-data-dir=/home/sanek02/.config/')20 options.add_argument("--auto-open-devtools-for-tabs")21 # options.headless = True22 # d = DesiredCapabilities.CHROME23 # d['loggingPrefs'] = {'browser': 'ALL'}24 options.add_experimental_option("excludeSwitches", ["enable-logging"])25 driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') #, desired_capabilities=d)26 driver.maximize_window()27 driver.get("https://test-front.onbank.online/?utm_source=mytarget&campaign_id=test&campaignid=test1&utm_campaign=test2&utm_term=hello&utm_content=urlss&yclid=testYCLID_1&rb_clickid=testRBCLICKID_1")28 driver.get_screenshot_as_png()29 yield driver30 driver.close()31def test_anketa_credit_card(driver_init):32 try:33 phone_number=autologin.random_phone_num_generator()34 #---------------------------------------------35 wait_of_element(xpath=web_elements.login_button_xpath,36 driver=driver_init).click()37 input_username = wait_of_element(xpath=web_elements.phone_xpath, driver=driver_init)38 input_username.clear()39 input_username.send_keys(phone_number)40 time.sleep(2) # чтобы записался номер в редис41 sms_code=autologin.get_code('7'+phone_number)42 input_code = wait_of_element(xpath=web_elements.sms_code_xpath, driver=driver_init)43 input_code.clear()44 input_code.send_keys(sms_code)45 time.sleep(1)46 # ---------------------------------------------47 # --------------Первый этап анкеты-------------48 # ---------------------------------------------49 clickable(xpath=web_elements.header_xpath,50 driver=driver_init).click()51 amount_input=wait_of_element(xpath=web_elements.amount_xpath, driver=driver_init)52 amount_input.clear()53 amount_input.send_keys(params.amount_sum)54 name_input=wait_of_element(xpath=web_elements.name_xpath,55 driver=driver_init)56 name_input.clear()57 name_input.send_keys(params.name)58 surname_input=wait_of_element(xpath=web_elements.surname_xpath,59 driver=driver_init)60 surname_input.clear()61 surname_input.send_keys(params.surname)62 patronymic_input = wait_of_element(xpath=web_elements.patronymic_xpath,63 driver=driver_init)64 patronymic_input.clear()65 patronymic_input.send_keys(params.patronymic)66 #Выбор пола (гендера)67 clickable(xpath=web_elements.find_male_xpath,68 driver=driver_init).click()69 clickable(xpath=web_elements.choose_male_xpath,70 driver=driver_init).click()71 #Нажимаем продолжить72 wait_of_element(xpath=web_elements.continue_button_one_xpath,73 driver=driver_init).click()74 #Закоменчено, потому что при входе с повторным номером телефона эти поля не отображаются75 # # ---------------Работаете ли вы---------------76 clickable(xpath=web_elements.work_or_not, driver=driver_init).click()77 # # ---------------------------------------------78 #79 # # ------------Работаете ли официально----------80 clickable(xpath=web_elements.official_or_not, driver=driver_init).click()81 # # ---------------------------------------------82 # ---------------------------------------------83 # --------------Второй этап анкеты-------------84 # ---------------------------------------------85 wait_of_element(xpath=web_elements.work_city_xpath,86 driver=driver_init).clear()87 work_city= wait_of_element(xpath=web_elements.work_city_xpath,88 driver=driver_init)89 work_city.send_keys(params.work_city)90 wait_of_element(xpath=web_elements.choose_work_city_xpath,91 driver=driver_init).click()92 #93 wait_of_element(xpath=web_elements.work_street_xpath,94 driver=driver_init).clear()95 work_street= wait_of_element(xpath=web_elements.work_street_xpath,96 driver=driver_init)97 work_street.send_keys(params.work_street)98 wait_of_element(xpath=web_elements.choose_work_street_xpath,99 driver=driver_init).click()100 #101 wait_of_element(xpath=web_elements.work_house_xpath,102 driver=driver_init).clear()103 work_street = wait_of_element(xpath=web_elements.work_house_xpath,104 driver=driver_init)105 work_street.send_keys(params.work_house_number)106 wait_of_element(xpath=web_elements.choose_work_house_xpath,107 driver=driver_init).click()108 #109 wait_of_element(xpath=web_elements.work_organization_xpath,110 driver=driver_init).clear()111 work_organization = wait_of_element(xpath=web_elements.work_organization_xpath,112 driver=driver_init)113 work_organization.send_keys(params.organization_name)114 wait_of_element(xpath=web_elements.choose_work_organization_xpath,115 driver=driver_init).click()116 # Начало работы на последнем рабочем месте (февраль, 2018)117 wait_of_element(xpath=web_elements.start_work_mounth_xpath,118 driver=driver_init).click()119 wait_of_element(xpath=web_elements.choose_start_work_mounth_xpath,120 driver=driver_init).click()121 wait_of_element(xpath=web_elements.start_work_year_xpath,122 driver=driver_init).click()123 wait_of_element(xpath=web_elements.choose_start_work_year_xpath,124 driver=driver_init).click()125 wait_of_element(xpath=web_elements.job_post_name_xpath,126 driver=driver_init).clear()127 job_post= wait_of_element(xpath=web_elements.job_post_name_xpath,128 driver=driver_init)129 job_post.send_keys(params.job_post_name)130 wait_of_element(xpath=web_elements.summary_income_xpath,131 driver=driver_init).clear()132 summary_income= wait_of_element(xpath=web_elements.summary_income_xpath,133 driver=driver_init)134 summary_income.send_keys(params.summary_income)135 wait_of_element(xpath=web_elements.continue_button_two_xpath,136 driver=driver_init).click()137 # ---------------------------------------------138 # --------------Третий этап анкеты-------------139 # ---------------------------------------------140 #Ваше образование (Высшее)141 wait_of_element(xpath=web_elements.education_xpath,142 driver=driver_init).click()143 wait_of_element(xpath=web_elements.choose_education_xpath,144 driver=driver_init).click()145 #Семейное положение (Замужем/женат)146 wait_of_element(xpath=web_elements.family_status_xpath,147 driver=driver_init).click()148 wait_of_element(xpath=web_elements.choose_family_status_xpath,149 driver=driver_init).click()150 # Дети до 18 лет (1)151 wait_of_element(xpath=web_elements.children_xpath,152 driver=driver_init).click()153 wait_of_element(xpath=web_elements.choose_children_xpath,154 driver=driver_init).click()155 # Наличие автомобиля (иномарка)156 wait_of_element(xpath=web_elements.car_xpath,157 driver=driver_init).click()158 wait_of_element(xpath=web_elements.choose_car_xpath,159 driver=driver_init).click()160 # Наличие недвижимости (квартира)161 wait_of_element(xpath=web_elements.flat_xpath,162 driver=driver_init).click()163 wait_of_element(xpath=web_elements.choose_flat_xpath,164 driver=driver_init).click()165 # Нажимаем "Продолжить"166 wait_of_element(xpath=web_elements.continue_button_three_xpath,167 driver=driver_init).click()168 # ---------------------------------------------169 # --------------Четвёртый этап анкеты----------170 # ---------------------------------------------171 #Дата рождения172 clickable(xpath=web_elements.birthdate_xpath,173 driver=driver_init).clear()174 birthdate = wait_of_element(xpath=web_elements.birthdate_xpath,175 driver=driver_init)176 birthdate.send_keys('\b\b\b\b\b\b\b\b\b\b\b\b\b\b')177 birthdate.send_keys(params.birthdate)178 #Место рождения179 wait_of_element(xpath=web_elements.birthplace_xpath,180 driver=driver_init).clear()181 birthplace = wait_of_element(xpath=web_elements.birthplace_xpath,182 driver=driver_init)183 birthplace.send_keys(params.birthplace)184 # Серия и номер паспорта185 wait_of_element(xpath=web_elements.passport_number_xpath,186 driver=driver_init).clear()187 passport_number = wait_of_element(xpath=web_elements.passport_number_xpath,188 driver=driver_init)189 passport_number.send_keys('\b\b\b\b\b\b\b\b\b\b\b\b\b\b')190 passport_number.send_keys(params.passport_number)191 # Дата выдачи паспорта192 wait_of_element(xpath=web_elements.passport_date_xpath,193 driver=driver_init).clear()194 passport_date = wait_of_element(xpath=web_elements.passport_date_xpath,195 driver=driver_init)196 passport_date.send_keys('\b\b\b\b\b\b\b\b\b\b\b\b\b\b')197 passport_date.send_keys(params.passport_date)198 # Код подразделения199 wait_of_element(xpath=web_elements.passport_code_xpath,200 driver=driver_init).clear()201 passport_code = wait_of_element(xpath=web_elements.passport_code_xpath,202 driver=driver_init)203 passport_code.send_keys(params.passport_code)204 wait_of_element(xpath=web_elements.choose_passport_code_xpath,205 driver=driver_init).click()206 #Адрес регистрации, город207 wait_of_element(xpath=web_elements.registration_city_xpath,208 driver=driver_init).clear()209 reg_city = wait_of_element(xpath=web_elements.registration_city_xpath,210 driver=driver_init)211 reg_city.send_keys(params.registration_city)212 wait_of_element(xpath=web_elements.choose_registration_city_xpath,213 driver=driver_init).click()214 # Адрес регистрации, улица215 wait_of_element(xpath=web_elements.registartion_street_xpath,216 driver=driver_init).clear()217 reg_street = wait_of_element(xpath=web_elements.registartion_street_xpath,218 driver=driver_init)219 reg_street.send_keys(params.registration_street)220 wait_of_element(xpath=web_elements.choose_registartion_street_xpath,221 driver=driver_init).click()222 # Адрес регистрации, дом223 wait_of_element(xpath=web_elements.registartion_house_xpath,224 driver=driver_init).clear()225 reg_street = wait_of_element(xpath=web_elements.registartion_house_xpath,226 driver=driver_init)227 reg_street.send_keys(params.registration_house)228 wait_of_element(xpath=web_elements.choose_registartion_house_xpath,229 driver=driver_init).click()230 # Адрес регистрации, квартира231 wait_of_element(xpath=web_elements.registartion_flat_xpath,232 driver=driver_init).clear()233 reg_street = wait_of_element(xpath=web_elements.registartion_flat_xpath,234 driver=driver_init)235 reg_street.send_keys(params.registration_flat)236 wait_of_element(xpath=web_elements.choose_registartion_flat_xpath,237 driver=driver_init).click()238 # Нажимаем "Продолжить"239 wait_of_element(xpath=web_elements.continue_button_four_xpath,240 driver=driver_init).click()241 time.sleep(10)242 driver_init.get_screenshot_as_file("Waiting.png")243 send_photo_Waiting(chat_id=bot_config.chat_id)244 time.sleep(50)245 driver_init.get_screenshot_as_file("Acceptance.png")246 send_photo_Acceptance(chat_id=bot_config.chat_id)247 # for entry in driver_init.get_log('browser'):248 # print(entry)249 print("\n Анкета заполнена и отправлена. Результаты высланы в телеграмм!")250 time.sleep(5)251 # Удаляем скриншоты с локальной машины252 remove_png()253 except Exception as e:254 print("\n Неудачная попытка ...", e)255 driver_init.quit()256if __name__ == '__main__':257 # test_redis_communication()...

Full Screen

Full Screen

test_inputs_page.py

Source:test_inputs_page.py Github

copy

Full Screen

1import pytest2from pages.inputs_page import InputsPage3from pages.login_page import LoginPage4@pytest.fixture(scope="function", autouse=True)5def setup(browser):6 link = "D:\Python\\test-task-protei-git\qa-test.html"7 login_page = LoginPage(browser, link)8 login_page.open()9 login_page.authorize_user()10 page = InputsPage(browser, browser.current_url)11 page.should_be_inputs_page()12 return page13# успешное добавление со всеми заполненными данными14def test_user_can_add_all_correct_data(browser, setup):15 page = setup16 page.fill_email_input("123@mail.ru")17 page.fill_name_input("name")18 web_elements = page.get_genders_in_selectbox()19 genders = [el.text for el in web_elements]20 gender = genders[0]21 page.select_gender(gender)22 page.select_data_11_checkbox()23 page.select_data_12_checkbox()24 page.select_data_22_radio_button()25 page.click_send_button()26 page.check_successful_add_message()27# возможность закрыть всплывающее окно об успешном добавлении28def test_user_can_close_successful_add_message(browser, setup):29 page = setup30 page.fill_email_input("123@mail.ru")31 page.fill_name_input("name")32 web_elements = page.get_genders_in_selectbox()33 genders = [el.text for el in web_elements]34 gender = genders[0]35 page.select_gender(gender)36 page.select_data_11_checkbox()37 page.select_data_12_checkbox()38 page.select_data_22_radio_button()39 page.click_send_button()40 page.check_successful_add_message()41 page.click_successful_add_message_ok_button()42 page.check_disappearing_successful_add_message()43# добавленная запись видна в таблице44# выбраны все чекбоксы45def test_user_can_see_all_filled_data_in_table(browser, setup):46 page = setup47 email = "123@mail.ru"48 name = "name"49 web_elements = page.get_genders_in_selectbox()50 genders = [el.text for el in web_elements]51 gender = genders[0]52 page.fill_email_input(email)53 page.fill_name_input(name)54 page.select_gender(gender)55 page.select_data_11_checkbox()56 page.select_data_12_checkbox()57 page.select_data_22_radio_button()58 page.click_send_button()59 page.check_successful_add_message()60 page.click_successful_add_message_ok_button()61 page.check_disappearing_successful_add_message()62 page.check_email_in_table(email, 1)63 page.check_name_in_table(name, 1)64 page.check_gender_in_table(gender, 1)65 page.check_choice_1_with_2_selected_options(1)66 page.check_choice_2("2.2", 1)67# добавленная запись видна в таблице68# в 1-м чекбоксе выбрана только одна запись69def test_user_can_see_added_data_in_table_with_selected_1_option_in_choice_1(browser, setup):70 page = setup71 email = "123@mail.ru"72 name = "name"73 web_elements = page.get_genders_in_selectbox()74 genders = [el.text for el in web_elements]75 gender = genders[0]76 page.fill_email_input(email)77 page.fill_name_input(name)78 page.select_gender(gender)79 page.select_data_11_checkbox()80 page.select_data_22_radio_button()81 page.click_send_button()82 page.check_successful_add_message()83 page.click_successful_add_message_ok_button()84 page.check_disappearing_successful_add_message()85 page.check_email_in_table(email, 1)86 page.check_name_in_table(name, 1)87 page.check_gender_in_table(gender, 1)88 page.check_choice_1_with_1_selected_options("1.1", 1)89 page.check_choice_2("2.2", 1)90# добавленная запись видна в таблице91# в 1-м чекбоксе ничего не выбрано, выбран только 2-й чекбокс92def test_user_can_see_added_data_in_table_with_selected_only_choice_2(browser, setup):93 page = setup94 email = "123@mail.ru"95 name = "name"96 web_elements = page.get_genders_in_selectbox()97 genders = [el.text for el in web_elements]98 gender = genders[0]99 page.fill_email_input(email)100 page.fill_name_input(name)101 page.select_gender(gender)102 page.select_data_22_radio_button()103 page.click_send_button()104 page.check_successful_add_message()105 page.click_successful_add_message_ok_button()106 page.check_disappearing_successful_add_message()107 page.check_email_in_table(email, 1)108 page.check_name_in_table(name, 1)109 page.check_gender_in_table(gender, 1)110 page.check_choice_1_with_1_selected_options("Нет", 1)111 page.check_choice_2("2.2", 1)112# добавленная запись видна в таблице113# оба чекбокса не выбраны114def test_user_can_see_added_data_in_table_without_checkboxes(browser, setup):115 page = setup116 email = "123@mail.ru"117 name = "name"118 web_elements = page.get_genders_in_selectbox()119 genders = [el.text for el in web_elements]120 gender = genders[0]121 page.fill_email_input(email)122 page.fill_name_input(name)123 page.select_gender(gender)124 page.click_send_button()125 page.check_successful_add_message()126 page.click_successful_add_message_ok_button()127 page.check_disappearing_successful_add_message()128 page.check_email_in_table(email, 1)129 page.check_name_in_table(name, 1)130 page.check_gender_in_table(gender, 1)131 page.check_choice_1_with_1_selected_options("Нет", 1)132 page.check_choice_2("", 1)133# неуспешное добавление134# появление сообщения о неверном формате почты135def test_user_cant_add_data_with_incorrect_email_format(browser, setup):136 page = setup137 page.fill_email_input("12345")138 page.fill_name_input("name")139 web_elements = page.get_genders_in_selectbox()140 genders = [el.text for el in web_elements]141 gender = genders[0]142 page.select_gender(gender)143 page.click_send_button()144 page.check_wrong_email_format_message()145# неуспешное добавление146# появление сообщения о незаполненном поле "имя"147def test_user_cant_add_data_with_empty_name_input(browser, setup):148 page = setup149 page.fill_email_input("123@mail.ru")150 page.fill_name_input("")151 web_elements = page.get_genders_in_selectbox()152 genders = [el.text for el in web_elements]153 gender = genders[0]154 page.select_gender(gender)155 page.click_send_button()156 page.check_wrong_empty_name_input_message()157# возможность закрыть сообщение о неверном формате почты158def test_user_can_close_wrong_email_format_message(browser, setup):159 page = setup160 page.fill_email_input("12345")161 page.fill_name_input("name")162 web_elements = page.get_genders_in_selectbox()163 genders = [el.text for el in web_elements]164 gender = genders[0]165 page.select_gender(gender)166 page.click_send_button()167 page.check_wrong_email_format_message()168 page.close_message()169 page.check_disappearing_wrong_email_format_message()170# возможность закрыть сообщение о незаполненном поле "имя"171def test_user_can_close_empty_name_input_message(browser, setup):172 page = setup173 page.fill_email_input("123@mail.ru")174 page.fill_name_input("")175 web_elements = page.get_genders_in_selectbox()176 genders = [el.text for el in web_elements]177 gender = genders[0]178 page.select_gender(gender)179 page.click_send_button()180 page.check_wrong_empty_name_input_message()181 page.close_message()182 page.check_disappearing_empty_name_input_message()183# неуспешное добавление с пустыми данными184def test_user_cant_add_empty_data(browser, setup):185 page = setup186 page.click_send_button()187 page.check_wrong_email_format_message()188# неуспешное добавление данных с только пробелами189def test_user_cant_add_spaces_data(browser, setup):190 page = setup191 page.fill_email_input(" ")192 page.fill_name_input(" ")193 page.click_send_button()194 page.check_wrong_email_format_message()195# успешное добавление данных с пробелами в начале196# проверка, что в таблице пробелы в начале убраны197def test_user_cant_add_spaces_before_data(browser, setup):198 page = setup199 email_with_spaces = " 123@mail.ru"200 name_with_spaces = " name"201 web_elements = page.get_genders_in_selectbox()202 genders = [el.text for el in web_elements]203 gender = genders[0]204 page.fill_email_input(email_with_spaces)205 page.fill_name_input(name_with_spaces)206 page.select_gender(gender)207 page.click_send_button()208 page.check_successful_add_message()209 page.click_successful_add_message_ok_button()210 page.check_disappearing_successful_add_message()211 page.check_email_in_table(email_with_spaces.lstrip(), 1)212 page.check_name_in_table(name_with_spaces.lstrip(), 1)213 page.check_gender_in_table(gender, 1)214 page.check_choice_1_with_1_selected_options("Нет", 1)...

Full Screen

Full Screen

extension_pages.py

Source:extension_pages.py Github

copy

Full Screen

1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4"""The generla class for extension pages."""5import web_elements6class ExtensionPages(object):7 """Contains all the functions of the options page of the extension."""8 def __init__(self, driver, url):9 """Constructor."""10 self._driver = driver11 self._url = url12 def go_to_page(self):13 """Go to options page if current page is not options page."""14 if self._driver.current_url != self._url:15 self._driver.get(self._url)16 self._driver.refresh()17 def _get_button(self, element_id, name=None):18 """Returns the button object on a page.19 @param element_id: The ID of the element20 @param name: The name of the button21 @return The button object22 """23 self.go_to_page()24 return web_elements.Button(self._driver, element_id, name)25 def _get_check_box(self, element_id, name=None):26 """Returns the check box object on a page.27 @param element_id: The ID of the element28 @param name: The name of the check box29 @return The check box object30 """31 self.go_to_page()32 return web_elements.CheckBox(self._driver, element_id, name)33 def _get_text_box(self, element_id, name=None):34 """Returns the text box object on a page.35 @param element_id: The ID of the element36 @param name: The name of the text box37 @return The text box object38 """39 self.go_to_page()40 return web_elements.TextBox(self._driver, element_id, name)41 def _get_radio_button(self, element_id, name=None):42 """Returns the radio button object on a page.43 @param element_id: The ID of the element44 @param name: The name of the radio button45 @return The radio button object46 """47 self.go_to_page()48 return web_elements.RadioButton(self._driver, element_id, name)49 def _get_scroll_box(self, element_id, name=None):50 """Returns the scroll box object on a page.51 Args:52 element_id: The ID of the element53 name: The name of the scroll box54 Returns:55 The scroll box object56 """57 self.go_to_page()58 return web_elements.ScrollBox(self._driver, element_id, name)59 def _get_web_element_box(self, element_id, name=None):60 """Returns the web element box object on a page.61 @param element_id: The ID of the element62 @param name: The name of the web element box63 @return The web element box object64 """65 self.go_to_page()66 return web_elements.WebElementBox(self._driver, element_id, name)67 def get_extension_version(self):68 """Returns the cast extension version based on its extension ID.69 @return The version number, in string, of the Cast extension70 """71 self.go_to_page()72 get_extension_version_js = ('return chrome.runtime.'73 'getManifest().version;')74 return self._driver.execute_script(get_extension_version_js)75 def get_extension_name(self):76 """Returns the cast extension name based on its extension ID.77 @return The name of the Cast extension78 """79 self.go_to_page()80 get_extension_name_js = 'return chrome.runtime.getManifest().name;'81 return self._driver.execute_script(get_extension_name_js)82 def execute_script(self, js_script):83 """Executes the javascript code in current page context.84 @param js_script: the javascript code to be executed.85 @return The value returned by javascript code.86 """87 self.go_to_page()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful