Best Python code snippet using pytractor_python
TractorScripts.py
Source: TractorScripts.py
...71 :type by: By72 :type value: str73 """74 if by is By.MODEL:75 element = self.find_element_by_model(value)76 elif by is By.BINDING:77 element = self.find_element_by_binding(value)78 elif by is By.BUTTON_TEXT:79 element = self.find_element_by_button_text(value)80 elif by is By.PARTIAL_BUTTON_TEXT:81 element = self.find_element_by_partial_button_text(value)82 elif by is By.REPEATER_ROWS:83 element = self.find_all_repeater_rows(value)84 else:85 element = super().find_element(by=by, value=value)86 if isinstance(element, (list,)):87 for elem in element:88 elem.selector = value89 else:90 element.selector = value91 if auto_wait:92 if not isinstance(element, (list,)):93 element.wait_visible(timeout=timeout, error=True)94 element.scroll_into_view()95 return element96 def find_elements(self, by=By.ID, value=None, auto_wait=True, timeout=20):97 """98 :param auto_wait: bool99 :param timeout: int100 :param wait_method: object101 :type by: By102 :type value: str103 """104 if by is By.MODEL:105 self.find_elements_by_model(value)106 elif by is By.BINDING:107 elements = self.find_elements_by_binding(value)108 elif by is By.BUTTON_TEXT:109 elements = self.find_elements_by_button_text(value)110 elif by is By.PARTIAL_BUTTON_TEXT:111 elements = self.find_elements_by_partial_button_text(value)112 elif by is By.REPEATER_ROWS:113 elements = self.find_all_repeater_rows(value)114 else:115 elements = super().find_elements(by=by, value=value)116 if isinstance(elements, (list,)):117 for elem in elements:118 elem.selector = value119 else:120 elements.selector = value121 if auto_wait:122 if not isinstance(elements, (list,)):123 # element.scroll_into_view()124 elements.wait_visible(timeout=timeout, error=True)125 return elements126 def _run_script(self, script, *args, **kwargs):127 _async = kwargs.pop('_async', False)128 new_args = tuple(['true' if x is True else x for x in list(args)]) if True in args else args129 if _async:130 return self.execute_async_script(script, *new_args, **kwargs), self._web_element_cls131 else:132 return self.execute_script(script, *new_args, **kwargs)133 def wait_for_angular(self):134 return self._run_script(self.waitForAngular, 'body', _async=True)135 @angular_wait_required136 def find_elements_by_model(self, model):137 return self._run_script(self.findByModel, model, _async=False)138 @angular_wait_required139 def find_element_by_model(self, model):140 return self.find_elements_by_model(model)[0]141 @angular_wait_required142 def find_elements_by_binding(self, bindings):143 return self._run_script(self.findBindings, bindings)144 @angular_wait_required145 def find_element_by_binding(self, binding):146 return self.find_elements_by_binding(binding)[0]147 @angular_wait_required148 def find_elements_by_option(self, options):149 return self._run_script(self.findByOptions, options)150 @angular_wait_required151 def find_element_by_option_value(self, option, value, show_first=True):152 opts = self.find_elements_by_option(option)153 results = []...
mixins.py
Source: mixins.py
...150 def find_elements_by_exact_binding(self, descriptor, using=None):151 elements = self._execute_client_script('findBindings', descriptor,152 True, using, async=False)153 return elements154 def find_element_by_model(self, descriptor, using=None):155 elements = self.find_elements_by_model(descriptor, using=using)156 if len(elements) == 0:157 raise NoSuchElementException(158 "No element found for model descriptor"159 " {}".format(descriptor)160 )161 else:162 return elements[0]163 @angular_wait_required164 def find_elements_by_model(self, descriptor, using=None):165 elements = self._execute_client_script('findByModel', descriptor,166 using, async=False)167 # Workaround for issue #10: findByModel.js returns None instead of empty168 # list if no element has been found....
test_locators.py
Source: test_locators.py
...61class ByModelLocatorTest(LocatorTestCase):62 def setUp(self):63 self.driver.get('index.html#/form')64 def test_find_element_by_model_finds_element_by_text_input_model(self):65 username = self.driver.find_element_by_model('username')66 name = self.driver.find_element_by_binding('username')67 username.clear()68 self.assertEqual(name.text, '')69 username.send_keys('Jane Doe')70 self.assertEqual(name.text, 'Jane Doe')71 username.clear()72 self.assertEqual(name.text, '')73 def test_find_element_by_model_finds_element_by_checkbox_input_model(self):74 shower = self.driver.find_element_by_id('shower')75 self.assertTrue(shower.is_displayed())76 colors = self.driver.find_element_by_model('show')77 colors.click()78 shower = self.driver.find_element_by_id('shower')79 self.assertFalse(shower.is_displayed())80 def test_find_element_by_model_finds_textarea_by_model(self):81 about = self.driver.find_element_by_model('aboutbox')82 self.assertEqual(about.get_attribute('value'), 'This is a text box')83 about.clear()84 about.send_keys('Something else to write about')85 self.assertEqual(about.get_attribute('value'),86 'Something else to write about')87 def test_find_elements_by_model_find_multiple_selects_by_model(self):88 selects = self.driver.find_elements_by_model('dayColor.color')89 self.assertEqual(len(selects), 3)90 def test_find_element_by_model_finds_the_selected_option(self):91 select = self.driver.find_element_by_model('fruit')92 selected_option = select.find_element_by_css_selector('option:checked')93 self.assertEqual(selected_option.text, 'apple')94 def test_find_element_by_model_finds_inputs_with_alternate_attribute_forms(95 self96 ):97 letter_list = self.driver.find_element_by_id('letterlist')98 self.assertEqual(letter_list.text, '')99 self.driver.find_element_by_model('check.w').click()100 self.assertEqual(letter_list.text, 'w')101 self.driver.find_element_by_model('check.x').click()102 self.assertEqual(letter_list.text, 'wx')103 def test_find_elements_by_model_finds_multiple_inputs(self):104 inputs = self.driver.find_elements_by_model('color')105 self.assertEqual(len(inputs), 3)106 def test_find_elements_by_model_returns_empty_list_if_nothing_found(self):107 """find_elements_by_model() should return an empty list if no elements108 have been found.109 This tests for issue #10 which comes from protractor's findByModel.js110 script.111 """112 result = self.driver.find_elements_by_model('this-model-does-not-exist')113 self.assertIsInstance(result, list)114 self.assertEqual(len(result), 0)115class ByRepeaterTestCase(LocatorTestCase):...
Check out the latest blogs from LambdaTest on this topic:
In today’s tech world, where speed is the key to modern software development, we should aim to get quick feedback on the impact of any change, and that is where CI/CD comes in place.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.
One of the most important tasks of a software developer is not just writing code fast; it is the ability to find what causes errors and bugs whenever you encounter one and the ability to solve them quickly.
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!