Best Python code snippet using robotframework-appiumlibrary_python
selenium.py
Source:selenium.py
...56 self.get_final_data()57 self.quit_driver()58 def go_to_edit(self):59 row = self.get_business_row()60 self.click_element(61 By.XPATH,62 (63 'td[2]/content/a',64 'td[3]/content/a',65 ),66 source=row67 )68 current_url = self.driver.current_url69 self.driver.get(current_url.replace('/dashboard/', '/edit/'))70 def get_business_row(self):71 if self.driver.current_url != 'https://business.google.com/locations':72 self.driver.get('https://business.google.com/locations')73 rows = self.get_elements(74 By.XPATH,75 (76 '/html/body/div[4]/c-wiz/div[2]/div[1]/c-wiz/div/c-wiz[3]'77 '/div/content/c-wiz[2]/div[2]/table/tbody/tr',78 '/html/body/div[7]/c-wiz/div[2]/div[1]/c-wiz/div/c-wiz[3]'79 '/div/content/c-wiz[2]/div[2]/table/tbody/tr'80 ),81 raise_exception=False,82 timeout=583 )84 if not rows:85 raise EmptyList(86 msg="There aren't any business", logger=self.logger87 )88 row = None89 for r in rows:90 if self.entity.name in r.text or self.entity.final_name in r.text:91 row = r92 break93 if not row:94 raise NotFound(msg="Business not found.", logger=self.logger)95 return row96 def do_open_verification_tab(self):97 row = self.get_business_row()98 status = self.get_element(99 By.XPATH,100 'td[3]',101 source=row102 ).text103 if status.strip() not in (104 'Verification required',105 'Pending verification',106 'Suspended',107 'Published'108 ):109 status = self.get_element(110 By.XPATH,111 'td[4]',112 source=row113 ).text114 if status.strip() == 'Published':115 raise EntityIsSuccess116 elif status.strip() == 'Suspended':117 raise EntityInvalid118 element = self.get_element(119 By.XPATH,120 (121 'td[4]/content/div/div',122 'td[5]/content/div/div'123 ),124 source=row125 )126 if platform.system() == 'Darwin':127 ActionChains(self.driver) \128 .key_down(Keys.COMMAND) \129 .click(element) \130 .key_up(Keys.COMMAND) \131 .perform()132 else:133 ActionChains(self.driver) \134 .key_down(Keys.CONTROL) \135 .click(element) \136 .key_up(Keys.CONTROL) \137 .perform()138 self.driver.switch_to.window(self.driver.window_handles[1])139 text = self.get_element(140 By.XPATH, '//body', move=False, timeout=5141 ).text.strip()142 if 'Is this your business' in text:143 elements = self.get_elements(144 By.XPATH,145 (146 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/'147 'div[1]/div/content/label[2]'148 )149 )150 self.click_element(151 By.XPATH,152 'div[1]',153 source=elements[-1],154 timeout=5155 )156 self.click_element(157 By.XPATH,158 (159 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/'160 'div[2]/button'161 )162 )163 text = self.get_element(164 By.XPATH, '//body', move=False, timeout=5165 ).text.strip()166 if (167 'Enter the code' not in text and168 'Get your code at this number now by automated call' not in text169 ):170 raise EntityInvalid(171 "Cannot validate by phone.", logger=self.logger172 )173 self.driver.switch_to.window(self.driver.window_handles[0])174 def do_final_name(self):175 if not self.entity.final_name:176 return177 self.click_element(178 By.XPATH,179 (180 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'181 'content/div[2]',182 ),183 timeout=5184 )185 xpath_input = (186 '//*[@id="js"]/div[9]/div/div[2]/content/div/div[4]/'187 'div/div[1]/div/div[1]/input'188 )189 self.clear_input(By.XPATH, xpath_input)190 self.fill_input(By.XPATH, xpath_input, self.entity.final_name)191 self.click_element(192 By.XPATH,193 (194 '//*[@id="js"]/div[9]/div/div[2]/content/div/div[5]/div[2]'195 ),196 )197 def do_final_category_1(self):198 if not self.entity.final_category_1:199 return200 self.click_element(201 By.XPATH,202 (203 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'204 'content/div[3]'205 ),206 timeout=self.WAIT_BEFORE_NEXT207 )208 xpath_input = (209 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'210 'div/div[1]/div/div[1]/div[1]/input[2]'211 )212 self.clear_input(213 By.XPATH,214 xpath_input,215 timeout=self.WAIT_BEFORE_INPUT216 )217 self.fill_input(218 By.XPATH,219 xpath_input,220 self.entity.final_category_1221 )222 self.click_element(223 By.XPATH,224 (225 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'226 'div/div[1]/div/div[1]/div[2]/div/div/div[1]'227 ),228 timeout=5229 )230 self.click_element(231 By.XPATH,232 (233 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]',234 ),235 )236 def do_service_area(self):237 self.click_element(238 By.XPATH,239 (240 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'241 'content/div[5]'242 ),243 timeout=self.WAIT_BEFORE_NEXT244 )245 xpath_input = (246 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/div[1]/'247 'div/div/div/div/div/div/div[1]/div[2]/div[1]/div/div[1]/input'248 )249 self.clear_input(By.XPATH, xpath_input, timeout=10)250 self.fill_input(251 By.XPATH,252 xpath_input,253 '{}, {}'.format(254 self.entity.final_city,255 self.entity.final_state256 )257 )258 self.click_element(259 By.XPATH,260 (261 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'262 'div/div[1]/div/div/div/div/div/div/div[2]/div/div/div[1]',263 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'264 'div/div[1]/div/div/div/div/div/div/div[3]/div/div/div[1]',265 )266 )267 self.click_element(268 By.XPATH,269 (270 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]'271 )272 )273 def do_hours(self):274 self.click_element(275 By.XPATH,276 (277 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'278 'content/div[6]'279 ),280 move=True,281 timeout=self.WAIT_BEFORE_INPUT282 )283 elements = self.get_elements(284 By.XPATH,285 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[3]/div/div',286 timeout=self.WAIT_BEFORE_NEXT287 )288 for element in elements:289 checkbox = self.get_element(290 By.XPATH,291 'label/div',292 source=element293 )294 if checkbox.get_attribute('aria-checked') != 'true':295 checkbox.click()296 self.click_element(297 By.XPATH,298 'div[2]/div[1]/div/div[1]/div[1]/input[2]',299 source=element300 )301 self.click_element(302 By.XPATH,303 'div[2]/div[1]/div/div[1]/div[2]/div/div/div[1]',304 source=element305 )306 self.click_element(307 By.XPATH,308 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div[2]'309 )310 def do_special_hours(self):311 self.click_element(312 By.XPATH,313 (314 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'315 'content/div[7]'316 ),317 move=True,318 timeout=self.WAIT_BEFORE_INPUT319 )320 self.click_element(321 By.XPATH,322 (323 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'324 'div[2]/div[1]/span[1]/div'325 ),326 raise_exception=False,327 timeout=self.WAIT_BEFORE_NEXT328 )329 self.click_element(330 By.XPATH,331 (332 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'333 'div[2]/div[3]/span[1]/div'334 ),335 raise_exception=False336 )337 self.click_element(338 By.XPATH,339 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]'340 )341 def do_website(self):342 if not self.entity.final_website:343 return344 self.click_element(345 By.XPATH,346 (347 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'348 'content/div[9]'349 ),350 move=True,351 timeout=self.WAIT_BEFORE_INPUT352 )353 xpath_input = (354 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div[1]/'355 'div[1]/div/div[1]/input'356 )357 self.clear_input(358 By.XPATH,359 xpath_input,360 timeout=self.WAIT_BEFORE_NEXT361 )362 self.fill_input(363 By.XPATH,364 xpath_input,365 self.entity.final_website366 )367 self.click_element(368 By.XPATH,369 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]'370 )371 def do_attributes(self):372 self.click_element(373 By.XPATH,374 (375 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'376 'content/div[10]'377 ),378 move=True,379 timeout=self.WAIT_BEFORE_NEXT380 )381 elements = []382 el = self.get_element(383 By.XPATH,384 '//*[@id="attr-dialog-content"]/div[9]',385 timeout=self.WAIT_BEFORE_INPUT,386 raise_exception=False387 )388 if el:389 elements.append(el)390 el = self.get_element(391 By.XPATH,392 '//*[@id="attr-dialog-content"]/div[10]',393 raise_exception=False394 )395 if el:396 elements.append(el)397 to_clic = randint(0, 1)398 special = False399 if not elements:400 elements = self.get_elements(401 By.XPATH,402 '//*[@id="attr-dialog-content"]/div'403 )404 to_clic = randint(1, 2)405 special = True406 element = elements[to_clic]407 if special:408 element = self.get_element(By.XPATH, 'div', source=element)409 if element.get_attribute('aria-checked') != 'true':410 element.click()411 self.click_element(412 By.XPATH,413 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]'414 )415 def do_description(self):416 if not self.entity.final_description:417 return418 self.click_element(419 By.XPATH,420 (421 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'422 'content/div[11]'423 ),424 move=True,425 timeout=self.WAIT_BEFORE_NEXT426 )427 xpath_input = (428 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'429 'div/div[1]/div[1]/textarea'430 )431 self.clear_input(432 By.XPATH,433 xpath_input,434 timeout=self.WAIT_BEFORE_INPUT435 )436 self.fill_input(By.XPATH, xpath_input, self.entity.final_description)437 self.click_element(438 By.XPATH,439 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]',440 timeout=5441 )442 def do_opening_date(self):443 self.click_element(444 By.XPATH,445 (446 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'447 'content/div[12]'448 ),449 move=True,450 timeout=self.WAIT_BEFORE_NEXT451 )452 date_start = int(datetime(2011, 1, 1).timestamp())453 date_end = int(datetime(2018, 12, 31).timestamp())454 date_final = randint(date_start, date_end)455 date_final = datetime.fromtimestamp(date_final)456 # Year457 xpath_year = (458 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'459 'div[1]/span[1]/div/div[1]/div/div[1]/input'460 )461 self.clear_input(By.XPATH, xpath_year, timeout=self.WAIT_BEFORE_INPUT)462 self.fill_input(By.XPATH, xpath_year, date_final.year)463 # Month464 xpath_month = (465 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div[1]/'466 'span[2]/span/div',467 )468 self.click_element(469 By.XPATH,470 xpath_month471 )472 self.click_element(473 By.XPATH,474 (475 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'476 'div[1]/span[2]/span/div/div[2]/div[{}]'477 ).format(date_final.month + 2),478 timeout=3479 )480 # Day481 self.click_element(482 By.XPATH,483 (484 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'485 'div[1]/span[3]/div'486 )487 )488 self.click_element(489 By.XPATH,490 (491 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'492 'div[1]/span[3]/div/div[2]/div[{}]'493 ).format(date_final.day + 2),494 timeout=3495 )496 # Apply497 self.click_element(498 By.XPATH,499 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]'500 )501 def do_code_fill(self):502 self.driver.switch_to_window(self.driver.window_handles[1])503 success = self.click_element(504 By.XPATH,505 (506 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/div/'507 'div[1]/div/div[2]/button[2]'508 ),509 raise_exception=False510 )511 if not success:512 self.click_element(513 By.XPATH,514 (515 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/'516 'div[2]/div/div[1]/button'517 ),518 )519 xpath_phone = (520 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/div/'521 'div[1]/div/div[1]/h3',522 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/h3/strong',523 )524 try:525 phone_number = self.get_element(526 By.XPATH,527 xpath_phone,528 move=False529 ).text530 except TimeoutException:531 phone_number = self.get_element(532 By.XPATH,533 xpath_phone,534 move=False,535 timeout=20536 ).text537 code = None538 retries = 0539 while not code:540 retries += 1541 if retries >= 10:542 raise MaxRetries(543 msg="Too mamny retries", logger=self.logger544 )545 try:546 code = self.entity.get_code(phone_number=phone_number)547 except Exception as err:548 print(err)549 code = None550 self._wait(2)551 self._wait(10)552 text = self.get_element(By.XPATH, '//body', move=False).text553 if "Couldn't connect" in text:554 raise InvalidValidationMethod555 xpath_code = (556 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/'557 'div[1]/div[2]/div[1]/div/div[1]/input'558 )559 self.clear_input(By.XPATH, xpath_code, timeout=5)560 self.fill_input(By.XPATH, xpath_code, code)561 def do_address(self):562 self.driver.switch_to_window(self.driver.window_handles[0])563 self.click_element(564 By.XPATH,565 (566 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'567 'content/div[4]'568 ),569 move=True,570 )571 self.click_element(572 By.XPATH,573 (574 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/'575 'div/div[3]/div[4]/div'576 ),577 timeout=self.WAIT_BEFORE_INPUT578 )579 # Input full address580 xpath_input_address = (581 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/div[3]/'582 'div[1]/div/div/div[2]/div/div/div[2]/input',583 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/div[3]/'584 'div[1]/c-wiz/c-wiz/div/div/div[4]/div/div[1]/div/div[1]/input'585 )586 self.fill_input(587 By.XPATH,588 xpath_input_address,589 (590 '{address} {city} {state} {zip_code}'.format(591 address=self.entity.final_address,592 city=self.entity.final_city,593 state=constants.STATES[self.entity.final_state],594 zip_code=self.entity.final_zip_code595 )596 )597 )598 # Zip Code599 xpath_zipcode = (600 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'601 'div[3]/div[1]/div/div/div[2]/div/div/div[6]/input',602 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'603 'div[3]/div[1]/c-wiz/c-wiz/div/div/div[7]/div/div[1]/div/'604 'div[1]/input',605 )606 self.fill_input(607 By.XPATH,608 xpath_zipcode,609 self.entity.final_zip_code,610 timeout=2611 )612 # City613 xpath_city = (614 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'615 'div[3]/div[1]/div/div/div[2]/div/div/div[4]/input',616 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'617 'div[3]/div[1]/c-wiz/c-wiz/div/div/div[5]/div/div[1]/div/'618 'div[1]/input',619 )620 self.fill_input(621 By.XPATH,622 xpath_city,623 self.entity.final_city,624 timeout=2625 )626 # State627 xpath_state = (628 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'629 'div[3]/div[1]/div/div/div[2]/div/div/div[5]/div[2]',630 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'631 'div[3]/div[1]/c-wiz/c-wiz/div/div/div[6]/div[1]'632 )633 self.click_element(634 By.XPATH,635 xpath_state,636 timeout=2637 )638 elements = self.get_elements(639 By.XPATH,640 (641 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'642 'div[3]/div[1]/div/div/div[2]/div/div/div[5]/div[3]/div',643 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div/'644 'div[3]/div[1]/c-wiz/c-wiz/div/div/div[6]/div[1]/div[2]/div'645 )646 )647 for element in elements:648 if element.text == constants.STATES[self.entity.final_state]:649 element.click()650 break651 # Clear and input address652 self.clear_input(By.XPATH, xpath_input_address)653 self.fill_input(654 By.XPATH,655 xpath_input_address,656 self.entity.final_address,657 timeout=2658 )659 self.click_element(660 By.XPATH,661 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[5]/div[2]',662 timeout=5663 )664 def do_phone(self):665 self.click_element(666 By.XPATH,667 (668 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[1]/div[2]/'669 'content/div[8]'670 ),671 move=True,672 timeout=self.WAIT_BEFORE_NEXT673 )674 xpath_input = (675 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[3]/div[1]/'676 'div/div/div[2]/div[1]/div/div[1]/input'677 )678 # Grab current number679 current_phone = self.get_element(680 By.XPATH, xpath_input, move=False, timeout=self.WAIT_BEFORE_INPUT681 ).get_attribute('value')682 # Fill new number683 self.clear_input(By.XPATH, xpath_input)684 self.fill_input(685 By.XPATH,686 xpath_input,687 self.entity.final_phone_number688 )689 if current_phone:690 self.click_element(691 By.XPATH,692 (693 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[3]/'694 'div[3]/div'695 )696 )697 self.fill_input(698 By.XPATH,699 (700 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[3]/'701 'div[3]/div[1]/div[1]/div/div[2]/div[1]/div/div[1]/input'702 ),703 current_phone,704 timeout=3705 )706 self.click_element(707 By.XPATH,708 '//*[@id="js"]/div[10]/div/div[2]/content/div/div[4]/div[2]'709 )710 def do_code_send(self):711 self.click_element(712 By.XPATH,713 (714 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/'715 'div[1]/div[3]/button'716 ),717 timeout=self.WAIT_BEFORE_INPUT718 )719 self._wait(60*5) # 5 Minutes720 def get_final_data(self):721 # Click "Get started"722 self.click_element(723 By.XPATH,724 (725 '//*[@id="main_viewpane"]/c-wiz[1]/div/div[2]/div/div/'726 'div[3]/button'727 )728 )729 # Click "Get started" again730 self.click_element(731 By.XPATH,732 (733 '//*[@id="js"]/div[10]/div/div[2]/div[3]/div',734 '//*[@id="js"]/div[9]/div/div[2]/div[3]/div'735 ),736 raise_exception=False,737 timeout=self.WAIT_BEFORE_INPUT738 )739 # Click "No thanks"740 self.click_element(741 By.XPATH,742 (743 '//*[@id="js"]/div[9]/div/div[2]/content/div/div[2]/div/'744 'div[4]/div[2]'745 ),746 raise_exception=False747 )748 # Click "X"749 self.click_element(750 By.XPATH,751 (752 '//*[@id="main_viewpane"]/div[2]/c-wiz/c-wiz/div/aside/'753 'div[2]/div/div/div'754 ),755 raise_exception=False756 )757 # Check if is "Pending" or "Suspended"758 text = self.get_element(759 By.XPATH,760 '//body',761 move=False762 ).text763 if 'This location has been suspended due to quality issues.' in text:...
scmedicaid.py
Source:scmedicaid.py
...32 def input_credentials(self):33 """34 Function that writes the credentials in the login form and submits it.35 """36 # self.browser.click_element('//a[text()="LOGIN"]')37 self.browser.input_text_when_element_is_visible('//input[@id="username"]', self.scmedicaid_login)38 self.browser.input_text_when_element_is_visible('//input[@id="password"]', self.scmedicaid_password)39 self.browser.click_element('//input[@id="submit_0"]')40 act_on_element('//div[@id="content"]', "find_element", 10)41 42 def select_provider(self):43 """44 Function that selects the correct provider45 """46 act_on_element('//select[@id="providerID2"]', "click_element")47 act_on_element('//select[@id="providerID2"]/option[text() = "{}"]'.format(self.provider_to_work), "click_element")48 act_on_element('//input[@id="update"]', "click_element")49 50 def populate_beneficiary_information(self, client_name: str):51 """52 Function that selects the beneficiary based on the client name found on CentralReach53 """...
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!!