How to use find_field method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

web_steps.py

Source:web_steps.py Github

copy

Full Screen

...123 return world.browser.find_element_by_xpath('//form[@action="%s"]' % url)124@step('I fill in "(.*?)" with "(.*?)"$')125def fill_in_textfield(step, field_name, value):126 with AssertContextManager(step):127 text_field = find_field(world.browser, 'text', field_name) or \128 find_field(world.browser, 'textarea', field_name) or \129 find_field(world.browser, 'password', field_name) or \130 find_field(world.browser, 'datetime', field_name) or \131 find_field(world.browser, 'datetime-local', field_name) or \132 find_field(world.browser, 'date', field_name) or \133 find_field(world.browser, 'month', field_name) or \134 find_field(world.browser, 'time', field_name) or \135 find_field(world.browser, 'week', field_name) or \136 find_field(world.browser, 'number', field_name) or \137 find_field(world.browser, 'range', field_name) or \138 find_field(world.browser, 'email', field_name) or \139 find_field(world.browser, 'url', field_name) or \140 find_field(world.browser, 'search', field_name) or \141 find_field(world.browser, 'tel', field_name) or \142 find_field(world.browser, 'color', field_name)143 assert_false(step, text_field is False,'Can not find a field named "%s"' % field_name)144 text_field.clear()145 text_field.send_keys(value)146 147@step('I focus on "(.*?)" and hit the (.*?) key')148def focus_and_press_key(step, field_name, key):149 with AssertContextManager(step):150 text_field = find_field(world.browser, 'text', field_name) or \151 find_field(world.browser, 'textarea', field_name) or \152 find_field(world.browser, 'password', field_name) or \153 find_field(world.browser, 'datetime', field_name) or \154 find_field(world.browser, 'datetime-local', field_name) or \155 find_field(world.browser, 'date', field_name) or \156 find_field(world.browser, 'month', field_name) or \157 find_field(world.browser, 'time', field_name) or \158 find_field(world.browser, 'week', field_name) or \159 find_field(world.browser, 'number', field_name) or \160 find_field(world.browser, 'range', field_name) or \161 find_field(world.browser, 'email', field_name) or \162 find_field(world.browser, 'url', field_name) or \163 find_field(world.browser, 'search', field_name) or \164 find_field(world.browser, 'tel', field_name) or \165 find_field(world.browser, 'color', field_name)166 assert_false(step, text_field is False,'Can not find a field named "%s"' % field_name)167 text_field.send_keys(getattr(Keys, key))168@step('I press (.*?) key')169def press_key(step, key):170 e = world.browser.find_element_by_css_selector('input:focus')171 e.send_keys(getattr(Keys, key))172@step('I press "(.*?)"$')173def press_button(step, value):174 with AssertContextManager(step):175 button = find_button(world.browser, value)176 button.click()177@step('I check "(.*?)"$')178def check_checkbox(step, value):179 with AssertContextManager(step):180 check_box = find_field(world.browser, 'checkbox', value)181 if not check_box.is_selected():182 check_box.click()183@step('I uncheck "(.*?)"$')184def uncheck_checkbox(step, value):185 with AssertContextManager(step):186 check_box = find_field(world.browser, 'checkbox', value)187 if check_box.is_selected():188 check_box.click()189@step('The "(.*?)" checkbox should be checked$')190def assert_checked_checkbox(step, value):191 check_box = find_field(world.browser, 'checkbox', value)192 assert_true(step, check_box.is_selected())193@step('The "(.*?)" checkbox should not be checked$')194def assert_not_checked_checkbox(step, value):195 check_box = find_field(world.browser, 'checkbox', value)196 assert_true(step, not check_box.is_selected())197@step('I select "(.*?)" from "(.*?)"$')198def select_single_item(step, option_name, select_name):199 with AssertContextManager(step):200 option_box = find_option(world.browser, select_name, option_name)201 option_box.click()202@step('I select the following from "(.*?)"$')203def select_multi_items(step, select_name):204 with AssertContextManager(step):205 # Ensure only the options selected are actually selected206 option_names = step.multiline.split('\n')207 select_box = find_field(world.browser, 'select', select_name)208 select = Select(select_box)209 select.deselect_all()210 for option in option_names:211 try:212 select.select_by_value(option)213 except NoSuchElementException:214 select.select_by_visible_text(option)215@step('The "(.*?)" option from "(.*?)" should be selected$')216def assert_single_selected(step, option_name, select_name):217 option_box = find_option(world.browser, select_name, option_name)218 assert_true(step, option_box.is_selected())219@step('The following options from "(.*?)" should be selected$')220def assert_multi_selected(step, select_name):221 with AssertContextManager(step):222 # Ensure its not selected unless its one of our options223 option_names = step.multiline.split('\n')224 select_box = find_field(world.browser, 'select', select_name)225 option_elems = select_box.find_elements_by_xpath('./option')226 for option in option_elems:227 if option.get_attribute('id') in option_names or \228 option.get_attribute('name') in option_names or \229 option.get_attribute('value') in option_names or \230 option.text in option_names:231 assert_true(step, option.is_selected())232 else:233 assert_true(step, not option.is_selected())234@step('I choose "(.*?)"$')235def choose_radio(step, value):236 with AssertContextManager(step):237 box = find_field(world.browser, 'radio', value)238 box.select()239@step('The "(.*?)" option should be chosen$')240def assert_radio_selected(step, value):241 box = find_field(world.browser, 'radio', value)242 assert_true(step, box.is_selected())243@step('The "(.*?)" option should not be chosen$')244def assert_radio_not_selected(step, value):245 box = find_field(world.browser, 'radio', value)246 assert_true(step, not box.is_selected())247 248 249 250 251 252 253def find_field_by_class(browser, attribute): 254 xpath = "//input[@class='%s']" % attribute 255 elems = browser.find_elements_by_xpath(xpath) 256 return elems[0] if elems else False 257 258@step('I fill in field with class "(.*?)" with "(.*?)"') 259def fill_in_textfield_by_class(step, field_name, value): ...

Full Screen

Full Screen

cartoonnetwork.py

Source:cartoonnetwork.py Github

copy

Full Screen

...19 }20 def _real_extract(self, url):21 display_id = self._match_id(url)22 webpage = self._download_webpage(url, display_id)23 def find_field(global_re, name, content_re=None, value_re='[^"]+', fatal=False):24 metadata_re = ''25 if content_re:26 metadata_re = r'|video_metadata\.content_' + content_re27 return self._search_regex(28 r'(?:_cnglobal\.currentVideo\.%s%s)\s*=\s*"(%s)";' % (global_re, metadata_re, value_re),29 webpage, name, fatal=fatal)30 media_id = find_field('mediaId', 'media id', 'id', '[0-9a-f]{40}', True)31 title = find_field('episodeTitle', 'title', '(?:episodeName|name)', fatal=True)32 info = self._extract_ngtv_info(33 media_id, {'networkId': 'cartoonnetwork'}, {34 'url': url,35 'site_name': 'CartoonNetwork',36 'auth_required': find_field('authType', 'auth type') != 'unauth',37 })38 series = find_field(39 'propertyName', 'series', 'showName') or self._html_search_meta('partOfSeries', webpage)40 info.update({41 'id': media_id,42 'display_id': display_id,43 'title': title,44 'description': self._html_search_meta('description', webpage),45 'series': series,46 'episode': title,47 })48 for field in ('season', 'episode'):49 field_name = field + 'Number'50 info[field + '_number'] = int_or_none(find_field(51 field_name, field + ' number', value_re=r'\d+') or self._html_search_meta(field_name, webpage))...

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