Best Python code snippet using toolium_python
agent.py
Source:agent.py
...82 83 def get_site_elements(self):84 #logging.debug("get_site_elements")85 html_code = self._get_html_code()86 elements = self._get_page_elements(self.html_code)87 self.site_elements = {88 'clickables': [elem.name for elem in elements['button']],89 'selectables': [], 90 'enterables': [elem.name for elem in elements['input']]91 }92 print("site_elements: {}".format(self.site_elements))93 return self.site_elements94 def action_on_element(self, action, element_number, data=None):95 """96 """97 print("action={}, element_number={}".format(action, element_number))98 action_to_element_type = {"CLICK": "button", "ENTER": "input"}99 element_type = action_to_element_type[action]100 element = self.page_elements[element_type][element_number]101 driver_element = self.driver.find_element_by_xpath(element.xpath)102 if action == "CLICK":103 print("Click on the element #{} with xpath={}".format(element_number, element.xpath))104 driver_element.click()105 self.logger.log("CLICK [{}]".format(element_number))106 time.sleep(self.delay_after_click)107 elif action == "ENTER":108 # driver_element.clear()109 data = self.data_generator.infer(element, self.html_code)110 print("Enter into the element #{} with xpath={}".format(element_number, element.xpath))111 driver_element.send_keys(data)112 self.logger.log("ENTER [{} ({})]: data=\"{}\"".format(element_number, element.name, data))113 return True114 """115 def click(self, current_element):116 #self.driver.find_element_by_xpath()117 element = self.driver.find_element_by_name(current_element)118 # the function find_element_by_name should be implemented119 element.click()120 def enter(self, current_element, data):121 element = self.driver.find_element_by_name(current_element)122 enter_field = self.driver.find_element_by_xpath("//input[@name='{}']".format(element))123 enter_field.clear()124 data = generate_data()125 enter_field.send_keys(data)126 """127 def is_target_achieved(self, targets=None):128 #return self.is_page_has_been_updated129 current_url = self._get_current_url()130 #print("current_url:", current_url)131 if targets:132 is_achieved = False133 final_targets = targets.get('final')134 for target in final_targets:135 target_url = target.get('url')136 if current_url == target_url:137 print("current_url is target_url:", target_url)138 self.logger.log("!current_url is target_url: {}".format(target_url))139 is_achieved = True140 else:141 elements = self._get_page_elements(self.html_code)142 inputs = elements['input']143 singin_window = False144 for input0 in inputs:145 if input0.name == "password":146 singin_window = True147 if not singin_window:148 print("The target is achieved. This is not a singin_window")149 is_achieved = not singin_window150 return is_achieved151 def _get_html_code(self):152 self.html_code = self.driver.page_source153 if self.previos_html_code is not None and self.previos_html_code != self.html_code:154 self.is_page_has_been_updated = True155 self.logger.log("page_has_been_updated")156 self.previos_html_code = self.html_code157 return self.html_code158 def _get_page_elements(self, html_code):159 html_soup = BeautifulSoup(html_code, 'lxml')160 elems = {}161 elems['input'] = html_soup.find_all('input')162 elems['button'] = html_soup.find_all('button')163 elements = {'input': [], 'button': []}164 for i, elem in enumerate(elems['input']):165 element_dict = {166 'id': i, # 0, 1, 2, ...167 'name': str(elem.attrs.get('name')), # like 'email'168 'type': str(elem.attrs.get('type')), # like 'email'169 'text': str(elem.attrs.get('placeholder')), # like 'email'170 'selenium_type': str(elem.name), # like 'input'171 'xpath': xpath_soup(elem),172 }...
page_object.py
Source:page_object.py
...12 def reset_object(self, driver_wrapper=None):13 if driver_wrapper:14 self.driver_wrapper = driver_wrapper15 self.app_strings = self.driver_wrapper.app_strings16 for element in self._get_page_elements():17 element.reset_object()18 def init_page_elements(self):19 pass20 def _get_page_elements(self):21 page_elements = []22 for attribute, value in list(self.__dict__.items()) + list(self.__class__.__dict__.items()):23 if attribute != 'parent' and isinstance(value, CommonObject):24 page_elements.append(value)25 return page_elements26 def wait_until_loaded(self, timeout=None):27 for element in self._get_page_elements():28 if hasattr(element, 'wait') and element.wait:29 from arc.page_elements import PageElement30 if isinstance(element, PageElement):31 element.wait_until_visible(timeout)32 if isinstance(element, PageObject):33 element.wait_until_loaded(timeout)...
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!!