How to use wait_for_element method in SeleniumBase

Best Python code snippet using SeleniumBase

ui_workflow.py

Source:ui_workflow.py Github

copy

Full Screen

...15 with open(location) as data_file:16 data = json.load(data_file)17 return data18 def login(self, user_name, password):19 sign_in_button = self.common_utilities.wait_for_element(self.ui_hash_map["sign_in_button"])20 self.common_utilities.click(sign_in_button)21 email_login_textfield = self.common_utilities.wait_for_element(self.ui_hash_map["email_login_textfield"])22 self.common_utilities.type_text_in_element(email_login_textfield, user_name)23 continue_button = self.common_utilities.wait_for_element(self.ui_hash_map["continue_button"])24 self.common_utilities.click(continue_button)25 password_login_textfield = self.common_utilities.wait_for_element(self.ui_hash_map["password_login_textfield"],26 20)27 self.common_utilities.click(password_login_textfield)28 self.common_utilities.type_text_in_element(password_login_textfield, password)29 sign_in_submit_button = self.common_utilities.wait_for_element(self.ui_hash_map["sign_in_submit_button"])30 self.common_utilities.click(sign_in_submit_button)31 if self.common_utilities.is_element_present(self.ui_hash_map["add_mobile_number_label"]):32 not_now_button = self.common_utilities.wait_for_element(self.ui_hash_map["not_now_button"])33 self.common_utilities.click(not_now_button)34 self.common_utilities.wait_for_element(self.ui_hash_map["action_bar_cart"])35 def select_country_as(self, country):36 hamburger_button = self.common_utilities.wait_for_element(self.ui_hash_map["hamburger_button"])37 self.common_utilities.click(hamburger_button)38 retry_count = 039 while not self.common_utilities.is_element_present(self.ui_hash_map["settings_button_in_side_panel"]) and retry_count < 5:40 self.common_utilities.swipe(True)41 time.sleep(2) # Waiting for loading refreshed contents42 retry_count += 143 settings_button_in_side_panel = self.common_utilities.wait_for_element(44 self.ui_hash_map["settings_button_in_side_panel"])45 self.common_utilities.click(settings_button_in_side_panel)46 select_country_button = self.common_utilities.wait_for_element(self.ui_hash_map["select_country_button"])47 self.common_utilities.click(select_country_button)48 country_region_selector = self.common_utilities.wait_for_element(self.ui_hash_map["country_region_selector"])49 self.common_utilities.click(country_region_selector)50 tmp_map = self.common_utilities.get_modified_copy("country_select_radio_button", "locator", "command", country)51 country_select_radio_button = self.common_utilities.wait_for_element(tmp_map)52 self.common_utilities.click(country_select_radio_button)53 done_button = self.common_utilities.wait_for_element(self.ui_hash_map["done_button"])54 self.common_utilities.click(done_button)55 self.common_utilities.wait_for_element(self.ui_hash_map["action_bar_cart"])56 def clear_cart_if_items_present(self):57 action_bar_cart = self.common_utilities.wait_for_element(self.ui_hash_map["action_bar_cart"])58 self.common_utilities.click(action_bar_cart)59 while self.common_utilities.is_element_present(self.ui_hash_map["delete_button"]):60 delete_button = self.common_utilities.wait_for_element(self.ui_hash_map["delete_button"])61 self.common_utilities.click(delete_button)62 hamburger_button = self.common_utilities.wait_for_element(self.ui_hash_map["hamburger_button"])63 self.common_utilities.click(hamburger_button)64 home_button_in_side_panel = self.common_utilities.wait_for_element(65 self.ui_hash_map["home_button_in_side_panel"])66 self.common_utilities.click(home_button_in_side_panel)67 def search_for_an_item(self, with_text):68 item_search_field = self.common_utilities.wait_for_element(self.ui_hash_map["item_search_field"])69 self.common_utilities.click(item_search_field)70 # full screen search option is seen once tap on search field71 item_search_field = self.common_utilities.wait_for_element(self.ui_hash_map["item_search_field"])72 self.common_utilities.type_text_in_element(item_search_field, with_text)73 tmp_map = self.common_utilities.get_modified_copy("dropdown_search_result", "locator", "command", with_text)74 dropdown_search_result = self.common_utilities.wait_for_element(tmp_map)75 self.common_utilities.click(dropdown_search_result)76 def select_product_from_search_result(self, with_name):77 tmp_map = self.common_utilities.get_modified_copy("product_title", "locator", "command", with_name)78 product_search_result = self.common_utilities.wait_for_element(tmp_map)79 self.common_utilities.click(product_search_result)80 if self.common_utilities.is_element_present(self.ui_hash_map["enter_pin_code_button"]):81 self.common_utilities.perform_tap()82 product_brand_name = self.common_utilities.wait_for_element(self.ui_hash_map["product_brand_name"])83 product_brand_name_value = self.common_utilities.get_text_of_element(product_brand_name)84 product_description_map = self.common_utilities.get_modified_copy("product_description", "locator", "command",85 with_name)86 product_description = self.common_utilities.wait_for_element(product_description_map)87 product_description_value = self.common_utilities.get_text_of_element(product_description)88 product_price = self.common_utilities.wait_for_element(self.ui_hash_map["product_price"])...

Full Screen

Full Screen

test_search.py

Source:test_search.py Github

copy

Full Screen

...7MAX_RESULTS = 508class SearchFrontendTest(ServiceInfoFrontendTestCase):9 def test_map_view(self):10 self.load_page_and_set_language()11 menu = self.wait_for_element('menu')12 search = menu.find_elements_by_link_text('Search')[0]13 search.click()14 self.wait_for_element('search_controls')15 self.assertHashLocation('/search')16 map_button = self.wait_for_element('[name="map-toggle-map"]', match=By.CSS_SELECTOR)17 map_button.click()18 self.wait_for_element('.search-map', match=By.CSS_SELECTOR)19 # While we're here, make sure the "request new service" button20 # has shown up21 button = self.wait_for_element('#request_service_button', match=By.CSS_SELECTOR)22 # Clicking it should go to the request a service page23 button.click()24 self.wait_for_element('#service-request', match=By.CSS_SELECTOR)25 self.assertHashLocation('/service/request')26 def test_search_list_results_limited(self):27 """No more than MAX_RESULTS services in result"""28 for i in range(MAX_RESULTS + 5):29 ServiceFactory(status=Service.STATUS_CURRENT)30 self.load_page_and_set_language()31 menu = self.wait_for_element('menu')32 search = menu.find_elements_by_link_text('Search')[0]33 search.click()34 self.wait_for_element('search_controls')35 self.assertHashLocation('/search')36 self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)37 results = self.browser.find_elements_by_css_selector('.search-result-list > li')38 self.assertEqual(MAX_RESULTS, len(results))39 # While we're here, make sure the "request new service" button40 # has shown up41 button = self.wait_for_element('#request_service_button', match=By.CSS_SELECTOR)42 # Clicking it should go to the request a service page43 button.click()44 self.wait_for_element('#service-request', match=By.CSS_SELECTOR)45 self.assertHashLocation('/service/request')46 def test_filtered_list_search(self):47 """Find services by type."""48 service = ServiceFactory(status=Service.STATUS_CURRENT)49 self.load_page_and_set_language()50 menu = self.wait_for_element('menu')51 search = menu.find_elements_by_link_text('Search')[0]52 search.click()53 form = self.wait_for_element('search_controls')54 self.assertHashLocation('/search')55 Select(form.find_element_by_name('type')).select_by_visible_text(56 service.type.name_en)57 controls = self.wait_for_element('map-toggle', match=By.CLASS_NAME)58 controls.find_element_by_name('map-toggle-list').click()59 try:60 result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)61 name = result.find_element_by_class_name('name')62 except StaleElementReferenceException:63 # Hit a race where we got a search element but then the page replaced it64 result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)65 name = result.find_element_by_class_name('name')66 self.assertEqual(name.text, service.name_en)67 def test_localized_search(self):68 """Search options and results should be localized."""69 service = ServiceFactory(status=Service.STATUS_CURRENT)70 self.load_page_and_set_language('fr')71 menu = self.wait_for_element('menu')72 search = menu.find_elements_by_link_text('Recherche')[0]73 search.click()74 form = self.wait_for_element('search_controls')75 self.assertHashLocation('/search')76 Select(form.find_element_by_name('type')).select_by_visible_text(77 service.type.name_fr)78 controls = self.wait_for_element('map-toggle', match=By.CLASS_NAME)79 controls.find_element_by_name('map-toggle-list').click()80 try:81 result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)82 name = result.find_element_by_class_name('name')83 name_text = name.text84 except StaleElementReferenceException:85 # Hit a race where we got a search element but then the page replaced it86 result = self.wait_for_element('.search-result-list > li', match=By.CSS_SELECTOR)87 name = result.find_element_by_class_name('name')88 name_text = name.text...

Full Screen

Full Screen

flight_search_page.py

Source:flight_search_page.py Github

copy

Full Screen

...14 def __init__(self, methods):15 self.methods = methods16 self.check()17 def check(self):18 self.methods.wait_for_element(self.SEARCH_CONTAINER)19 self.methods.wait_for_element(self.ORIGIN_INPUT)20 self.methods.wait_for_element(self.DESTINATION_INPUT)21 self.methods.wait_for_element(self.DEPARTURE_BTN)22 self.methods.wait_for_element(self.RETURN_BTN)23 self.methods.wait_for_element(self.SEARCH_FLIGHT)24 def fill_origin(self):25 self.methods.wait_for_element(self.ORIGIN_INPUT).click()26 self.methods.wait_for_element(self.ORIGIN_INPUT).send_keys(self.methods.get_from_ini("origin_city"))27 self.methods.wait_for_element((By.CSS_SELECTOR, self.CITY_SELECTOR.format(28 self.methods.get_from_ini("origin_city_code")))).click()29 return self.methods.wait_for_element(self.ORIGIN_INPUT).get_attribute("value")30 def fill_destination(self):31 self.methods.wait_for_element(self.DESTINATION_INPUT).click()32 self.methods.wait_for_element(self.DESTINATION_INPUT).send_keys(self.methods.get_from_ini("destination_city"))33 self.methods.wait_for_element((By.CSS_SELECTOR, self.CITY_SELECTOR.format(34 self.methods.get_from_ini("destination_city_code")))).click()35 return self.methods.wait_for_element(self.DESTINATION_INPUT).get_attribute("value")36 def fill_departure(self):37 self.methods.wait_for_element(self.DEPARTURE_BTN).click()38 self.methods.wait_for_element(self.DATE_PICKER)39 self.methods.wait_for_element((By.CSS_SELECTOR, self.DAY_SELECTOR.format(40 self.methods.get_from_ini("departure_date")))).click()41 time.sleep(0.2)42 def fill_return(self):43 self.methods.wait_for_element(self.RETURN_BTN).click()44 self.methods.wait_for_element(self.DATE_PICKER)45 self.methods.wait_for_element((By.CSS_SELECTOR, self.DAY_SELECTOR.format(46 self.methods.get_from_ini("return_date")))).click()47 time.sleep(0.2)48 def search_flights(self):49 self.methods.wait_for_element(self.SEARCH_FLIGHT).click()...

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 SeleniumBase 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