How to use find_any_field method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

webdriver.py

Source:webdriver.py Github

copy

Full Screen

...163)164@step('I fill in "(.*?)" with "(.*?)"$')165def fill_in_textfield(step, field_name, value):166 with AssertContextManager(step):167 date_field = find_any_field(world.browser,168 DATE_FIELDS,169 field_name)170 if date_field:171 field = date_field172 else:173 field = find_any_field(world.browser,174 TEXT_FIELDS,175 field_name)176 assert_true(step, field,177 'Can not find a field named "%s"' % field_name)178 if date_field:179 field.send_keys(Keys.DELETE)180 else:181 field.clear()182 field.send_keys(value)183@step('I press "(.*?)"$')184def press_button(step, value):185 with AssertContextManager(step):186 button = find_button(world.browser, value)187 button.click()188@step('I click on label "([^"]*)"')189def click_on_label(step, label):190 """191 Click on a label192 """193 with AssertContextManager(step):194 elem = world.browser.find_element_by_xpath(str(195 '//label[normalize-space(text()) = "%s"]' % label))196 elem.click()197@step(r'Element with id "([^"]*)" should be focused')198def element_focused(step, id):199 """200 Check if the element is focused201 """202 elem = world.browser.find_element_by_xpath(str('id("{id}")'.format(id=id)))203 focused = world.browser.switch_to_active_element()204 assert_true(step, elem == focused)205@step(r'Element with id "([^"]*)" should not be focused')206def element_not_focused(step, id):207 """208 Check if the element is not focused209 """210 elem = world.browser.find_element_by_xpath(str('id("{id}")'.format(id=id)))211 focused = world.browser.switch_to_active_element()212 assert_false(step, elem == focused)213@step(r'Input "([^"]*)" (?:has|should have) value "([^"]*)"')214def input_has_value(step, field_name, value):215 """216 Check that the form input element has given value.217 """218 with AssertContextManager(step):219 text_field = find_any_field(world.browser,220 DATE_FIELDS + TEXT_FIELDS,221 field_name)222 assert_false(step, text_field is False,223 'Can not find a field named "%s"' % field_name)224 assert_equals(text_field.get_attribute('value'), value)225@step(r'I submit the only form')226def submit_the_only_form(step):227 """228 Look for a form on the page and submit it.229 """230 form = world.browser.find_element_by_xpath(str('//form'))231 form.submit()232@step(r'I submit the form with id "([^"]*)"')233def submit_form_id(step, id):...

Full Screen

Full Screen

lettuce_webdriver.py

Source:lettuce_webdriver.py Github

copy

Full Screen

...162)163@step('I fill in "(.*?)" with "(.*?)"$')164def fill_in_textfield(step, field_name, value):165 with AssertContextManager(step):166 date_field = find_any_field(world.browser,167 DATE_FIELDS,168 field_name)169 if date_field:170 field = date_field171 else:172 field = find_any_field(world.browser,173 TEXT_FIELDS,174 field_name)175 assert_true(step, field,176 'Can not find a field named "%s"' % field_name)177 if date_field:178 field.send_keys(Keys.DELETE)179 else:180 field.clear()181 field.send_keys(value)182@step('I press "(.*?)"$')183def press_button(step, value):184 with AssertContextManager(step):185 button = find_button(world.browser, value)186 button.click()187@step('I click on label "([^"]*)"')188def click_on_label(step, label):189 """190 Click on a label191 """192 with AssertContextManager(step):193 elem = world.browser.find_element_by_xpath(str(194 '//label[normalize-space(text()) = "%s"]' % label))195 elem.click()196@step(r'Element with id "([^"]*)" should be focused')197def element_focused(step, id):198 """199 Check if the element is focused200 """201 elem = world.browser.find_element_by_xpath(str('id("{id}")'.format(id=id)))202 focused = world.browser.switch_to_active_element()203 assert_true(step, elem == focused)204@step(r'Element with id "([^"]*)" should not be focused')205def element_not_focused(step, id):206 """207 Check if the element is not focused208 """209 elem = world.browser.find_element_by_xpath(str('id("{id}")'.format(id=id)))210 focused = world.browser.switch_to_active_element()211 assert_false(step, elem == focused)212@step(r'Input "([^"]*)" (?:has|should have) value "([^"]*)"')213def input_has_value(step, field_name, value):214 """215 Check that the form input element has given value.216 """217 with AssertContextManager(step):218 text_field = find_any_field(world.browser,219 DATE_FIELDS + TEXT_FIELDS,220 field_name)221 assert_false(step, text_field is False,222 'Can not find a field named "%s"' % field_name)223 assert_equals(text_field.get_attribute('value'), value)224@step(r'I submit the only form')225def submit_the_only_form(step):226 """227 Look for a form on the page and submit it.228 """229 form = world.browser.find_element_by_xpath(str('//form'))230 form.submit()231@step(r'I submit the form with id "([^"]*)"')232def submit_form_id(step, id):...

Full Screen

Full Screen

steps.py

Source:steps.py Github

copy

Full Screen

...14def fill_bootstrap_field(step, text, field):15 words_list = field.lower().split()16 words_list.insert(0, "id")17 id_field = "_".join(words_list)18 date_field = find_any_field(world.browser, TEXT_FIELDS, id_field)19 date_field.send_keys(text)20@step(r'I type in "(.*)" to id "(.*)"')21def fill_bootstrap_field(step, text, id_field):22 date_field = find_any_field(world.browser, TEXT_FIELDS, id_field)23 date_field.send_keys(text)24@step(r'I click on an element with id of "(.*)"')25def click_on_element_by_id(step, id):26 try:27 elem = world.browser.find_element_by_id(id)28 except NoSuchElementException:29 raise AssertionError("Element with ID '{}' not found.".format(id))30 elem.click()31@step(r'I click on an element "(.*)" called "(.*)"')32def click_on_element_by_value(step, value, typeelement):33 try:34 text = find_field_by_value(world.browser, typeelement)35 except NoSuchElementException:36 raise AssertionError("Element not found.")...

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