Best Python code snippet using SeleniumBase
page.py
Source:page.py
...416 dep = args['path']417 self.waitForNameVisible(dep, 30)418 self.driver.find_element_by_name(dep).click()419 # print('Ðлик', dep)420 def click_xpath(self, args):421 xpath = args['path']422 self.waitForElementClickable(xpath, 30)423 self.driver.find_element_by_xpath(xpath).click()424 def click_css(self, args):425 css = args['path']426 print('css = ', css)427 # self.waitForElementClickable(css, 30)428 self.driver.find_element_by_css_selector(css).click()429 def click_switch_to(self, args):430 frame = args['path']431 index = args['index']432 # self.waitForElementClickable(css, 30)433 self.driver.switch_to.frame(self.driver.find_elements_by_tag_name(frame)[index]).click()434 def click_s_xpath(self, args):435 xpath = args['path']436 index = args['index']437 self.waitForElementClickable(xpath, 30)438 self.driver.find_elements_by_xpath(xpath)[index].click()439 def double(self, args):440 self.click_xpath(args['path_1'])441 self.click_xpath(args['path_2'])442 def click_tag(self, args):443 self.driver.find_element_by_tag_name(args['path']).send_keys(args['send'])444 #ÐÑовеÑка видимоÑÑи ÑлеменÑа #Exception445 def tester_vis_xpath(self, xpath):446 self.waitForElementVisible(xpath, 5)447 self.driver.find_element_by_xpath(xpath)448 # print('Ðлик', dep)449 #ÐÑовеÑка кликабелÑноÑÑи ÑлеменÑа450 def tester_click_xpath(self, xpath):451 self.waitForElementClickable(xpath, 25)452 self.driver.find_element_by_xpath(xpath)453 # print('Ðлик', dep)454 #Ðнопки455 def click_play(self):456 xpath = '//*[@id="clip-player"]/div[16]'457 self.waitForElementClickable(xpath, 35)458 self.driver.find_element_by_xpath(xpath).click()459 # # print('Ðлик', dep)460 def click_stop(self):461 # xpath = '//*[@id="clip-player"]/div[4]'462 xpath = '//*[@id="clip-player"]/div[4]/div'463 # xpath = '//*[@id="clip-player"]/div[3]'464 css_sel = '#clip-player > div.tvz-button.tvz-button_play > div'465 # self.waitForElementClickable(xpath, 15)466 time.sleep(SLEEP_SHORT)467 self.driver.find_element_by_xpath(xpath).click()468 # self.driver.find_element_by_css_selector(css_sel).click()469 # print('Ðлик', dep)470 def click_enter(self):471 self.click_xpath('.//button[@class="header__login"]')472 def waitForElementPresent(self, xpath, timer):473 WebDriverWait(self.driver, timer).until(EC.presence_of_element_located((By.XPATH, xpath)))474 def waitForElementClickable(self, xpath, timer):475 WebDriverWait(self.driver, timer).until(EC.element_to_be_clickable((By.XPATH, xpath)))476 def waitForElementVisible(self, xpath, timer):477 WebDriverWait(self.driver, timer).until(EC.presence_of_element_located((By.XPATH, xpath)))478 def waitForNameVisible(self, name, timer):479 WebDriverWait(self.driver, timer).until(EC.presence_of_element_located((By.NAME, name)))480 def waitForIDVisible(self, id, timer):481 WebDriverWait(self.driver, timer).until(EC.presence_of_element_located((By.ID, id)))482 # OPERATIONS483 # ФÑнкÑÐ¸Ñ Ð²Ð²Ð¾Ð´Ð°484 def send_id(self, args):485 d_id = args['path']486 txt = args['text']487 # self.loger_info('path = ' + d_id + ', text = ' + txt)488 self.waitForIDVisible(d_id, 30)489 self.driver.find_element_by_id(d_id).send_keys(txt)490 return491 def send_name(self, args):492 d_name = args['path']493 txt = args['text']494 self.waitForNameVisible(d_name, 30)495 self.driver.find_element_by_name(d_name).send_keys(txt)496 return497 def send_css(self, args):498 d_name = args['path']499 txt = args['text']500 self.driver.find_element_by_css_selector(d_name).send_keys(txt)501 return502 # ФÑнкÑÐ¸Ñ Ð²Ð²Ð¾Ð´Ð°503 def input(self, dclass, data):504 li_xpath = ('.//input[@class="%s"]' % dclass)505 # self.waitForElementClickable(li_xpath, 80)506 time.sleep(SLEEP_SHORT)507 self.driver.find_element_by_xpath(li_xpath).send_keys(data)508 def rand_mail(self, lit):509 d = str(datetime.today())510 ds = d.replace('-', '')511 d = ds.split(':')[0]512 d_2 = ds.split(':')[1]513 d_3 = d.replace(' ', '')514 rand = d_3 + d_2515 # self.loger_info(rand)516 random_mail = 'tvzavrtest' + rand + lit + '@rrbbxvdr.rz'517 return (random_mail, rand)518 # def rand_number(self, lit):519 # d = str(datetime.today())520 # ds = d.replace('-', '')521 # d = ds.split(':')[0]522 # d_2 = ds.split(':')[1]523 # d_3 = d.replace(' ', '')524 # rand = d_3 + d_2525 # self.loger_info(rand)526 # random_number = rand + lit527 # return (random_number, rand)528 def code_phone(self, phone):529 self.loger_info('ÐолÑÑение кода на ÑелеÑон: ' + phone)530 # url = 'http://www.tvzavr.ru/api/3.1/sms/send_confirm_code?phone=' + str(phone) + '&entity=empty&prv=smsfake_tvz'531 url = 'http://www.tvzavr.ru/api/3.1/sms/send_confirm_code?phone=' + str(532 phone) + '&entity=empty&prv=smstest_tvz' # полÑÑилоÑÑ Ñ ÑÑой533 self.loger_info(url)534 code = (requests.get(url)).text535 self.loger_info('code_phone ' + code)536 r_code = code.split(':')[3]537 s_code = r_code.split('"')[1]538 self.loger_info(s_code)539 return s_code540 # ФÑнкÑÐ¸Ñ Ð¿ÑовеÑки налиÑÐ¸Ñ ÑлеменÑов на ÑÑÑаниÑе.541 def elem(self):542 self.loger('ÐÑовеÑка ÑлеменÑов ÑÑÑаниÑÑ')543 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "Ðовинки""544 res_txt = str(ResultPage.find_link(self, "a", "header__link"))545 self.loger(res_txt)546 # Ðовинки - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи547 assert ('Ðовинки') in res_txt548 self.loger('ÐалиÑие ÑÑÑлки "Ðовинки" подÑвеÑждено')549 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "ÐодпиÑки""550 res_txt = str(ResultPage.find_all_link(self, "a", "header__link"))551 # ÐодпиÑки - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи552 assert ('ÐодпиÑки') in res_txt553 self.loger('ÐалиÑие ÑÑÑлки "ÐодпиÑки" подÑвеÑждено')554 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "ÐеÑплаÑно""555 # ÐеÑплаÑно - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи556 assert ('ÐеÑплаÑно') in res_txt557 self.loger('ÐалиÑие ÑÑÑлки "ÐеÑплаÑно" подÑвеÑждено')558 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "ÐодбоÑки"559 # ÐодбоÑки - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи560 assert ('ÐодбоÑки') in res_txt561 self.loger('ÐалиÑие ÑÑÑлки "ÐодбоÑки" подÑвеÑждено')562 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "ÐаÑалог""563 # ÐаÑалог - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи564 assert ('ÐаÑалог') in res_txt565 self.loger('ÐалиÑие ÑÑÑлки "ÐаÑалог" подÑвеÑждено')566 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "ÐеÑÑм""567 # ÐеÑÑм - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи568 assert ('ÐеÑÑм') in res_txt569 self.loger('ÐалиÑие ÑÑÑлки "ÐеÑÑм" подÑвеÑждено')570 # ÐÑовеÑка налиÑÐ¸Ñ ÑÑÑлки "ÐÑ
од""571 res_txt = str(ResultPage.find_link(self, "button", "header__login"))572 # ÐÑ
од - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи573 assert ('ÐÑ
од') in res_txt574 self.loger(res_txt)575 self.loger('ÐалиÑие ÑÑÑлки "ÐÑ
од" подÑвеÑждено')576 def loger(self, text):577 logging.basicConfig(format=u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s',578 level=logging.DEBUG)579 logging.info(text)580 print(text)581 def loger_info(self, text):582 logging.basicConfig(format=u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s',583 level=logging.DEBUG)584 logging.info(text)585 print(text)586 def loger_error(self, text):587 logging.basicConfig(format=u'%(filename)s[LINE:%(lineno)d]# %(levelname)-8s [%(asctime)s] %(message)s',588 level=logging.DEBUG)589 logging.error(text)590 print(text)591 # def send_sms(self, phone, message): # ФÑнкÑÐ¸Ñ Ð¾ÑпÑавки ÑмÑ592 # logging.info("ÐÑзов ÑÑнкÑии оÑпÑавки СÐС")593 # # chrome_options = webdriver.ChromeOptions()594 # # chrome_options.add_argument("user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data") # ÐапÑÑк бÑаÑзеÑа Ñ ÑоÑ
ÑаненнÑм пÑоÑилем595 # self.driver = webdriver.Chrome("C:\chromedriver\chromedriver.exe")596 self.driver.get("https://app.mysms.com/")597 self.driver.implicitly_wait(10)598 time.sleep(SLEEP_MEDIUM)599 self.driver.find_element_by_xpath('.//div[@class="gwt-Label"]').click() # Ðовое ÑообÑение600 time.sleep(SLEEP_SHORT)601 self.driver.find_element_by_xpath('.//input[@class="recipientTextBox"]').send_keys(phone)602 time.sleep(SLEEP_SHORT)603 self.driver.find_element_by_xpath('.//div[@class="textarea"]').send_keys(message)604 time.sleep(SLEEP_SHORT)605 self.driver.find_element_by_xpath('.//button[@class="styledButton sendButton sim dropdown"]').click()606 logging.info("Ðлик 'ÐÑпÑавиÑÑ' пÑоизведен, СÐС подÑвеÑÐ¶Ð´ÐµÐ½Ð¸Ñ Ð¾ÑпÑавлено")607 self.driver.close()608 return609 def login_google(self, emailgo, passok):610 time.sleep(SLEEP_SHORT)611 self.send_f('Ðвод_логин_Google', emailgo, 1)612 time.sleep(2)613 self.click_f('Ðлик_кнопки_Ðалее_Google', 6)614 time.sleep(2)615 self.send_f('Ðвод_паÑолÑ_Google', passok, 1)616 time.sleep(2)617 self.click_f('Ðлик_кнопки_Ðалее_Google', 6)618 time.sleep(2)619 return620 # def login_match(self, emailt, passw):621 # time.sleep(SLEEP_SHORT)622 # self.send_f('Ðвод_name_логина', emailt, 2)623 # self.send_f('Ðвод_паÑолÑ_tvz', passw, 3)624 # self.click_f('Ðлик_ÐойÑи_auth', 4)625 # time.sleep(SLEEP_MEDIUM)626 # return 06.08.2019627 def login_matchtv(self, num_phone, passw):628 self.click_f('ÐÑ
од', 1)629 time.sleep(1)630 self.click_f('ÐÑ
од2', 2)631 time.sleep(2)632 self.driver.find_element_by_xpath('.//input[@type="tel"]').send_keys(num_phone)633 self.loger_info('ÐведÑн Ð½Ð¾Ð¼ÐµÑ ÑелеÑона: +7 ' + num_phone)634 time.sleep(1)635 self.click_f('Ðалее', 3)636 time.sleep(1)637 self.driver.find_element_by_xpath('.//input[@type="password"]').send_keys(passw)638 self.loger_info('ÐведÑн паÑолÑ: ' + passw)639 time.sleep(1)640 self.click_f('ÐойÑи', 4)641 time.sleep(1)642 return643 # def login_tvzavr(self, email, passw, sex):644 # result = ResultPage(self.driver)645 # prof = Profile(self.driver)646 # self.waitForElementVisible('.//button[@class="header__login"]', 7)647 # resic = result.find_link("button", "header__login")648 # if "ÐÑ
од" not in resic:649 # if sex == 'male':650 # prof.click_f('Ðлик_ÐваÑаÑка_Ð', 1)651 # else:652 # prof.click_f('Ðлик_ÐваÑаÑка_Ð', 1)653 #654 # prof.click_f('Ðлик_ÐÑйÑи', 1)655 # else:656 # # Шаг 1 ÐажаÑÑ Ð² Ñапке на ÐºÐ½Ð¾Ð¿ÐºÑ "ÐÑ
од".')657 # self.click_f('Ðлик_ÐÑ
од', 1)658 # time.sleep(SLEEP_SHORT)659 # # Шаг 2660 # self.send_f('Ðвод_name_логина', email, 2)661 # self.send_f('Ðвод_паÑолÑ_Google', passw, 3)662 # self.click_f('Ðлик_ÐойÑи_auth', 4)663 # time.sleep(SLEEP_LONG)664 # try:665 # self.click_f('Ðлик_кнопки_кÑеÑÑик', 6)666 # except:667 # print('Ð½ÐµÑ Ð°ÐºÑии миÑÑбиÑи')668 # Шаг 5669 # if sex == 'male': 1.08.2019670 # prof.click_f('Ðлик_ÐваÑаÑка_Ð', 7)671 # else:672 # prof.click_f('Ðлик_ÐваÑаÑка_Ð', 8)673 # time.sleep(SLEEP_MEDIUM)674 # return675 def login_mailru(self, emailru, passw):676 self.send_id('mailbox:login', emailru)677 self.loger_info('Ðвод логина на mail.ru ' + emailru + 'пÑоизведен')678 time.sleep(SLEEP_SHORT)679 self.send_id('mailbox:password', passw)680 self.loger_info('Ðвод паÑÐ¾Ð»Ñ Ð½Ð° mail.ru пÑоизведен')681 time.sleep(SLEEP_SHORT)682 self.driver.find_element_by_xpath('.//input[@class="o-control"]').click()683 self.loger_info('Ðлик кнопки "ÐойÑи" на mail.ru пÑоизведен')684 time.sleep(SLEEP_MEDIUM)685 def registration(self, email, passw):686 result = ResultPage(self.driver)687 prof = Profile(self.driver)688 resic = result.find_link("button", "header__login tvz-unauthorized")689 if "ÐÑ
од" not in resic:690 prof.click_f('Ðлик_ÐваÑаÑка_Ð', 1)691 self.loger_info('Шаг 0 Ðлик на аваÑаÑÐºÑ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ Ð¿Ñоизведен')692 self.driver.find_element_by_xpath('.//button[@class="profile-menu__logout js-profile-logout"]').click()693 time.sleep(SLEEP_SHORT)694 else:695 self.click_enter()696 self.loger_info('Шаг 1 Ðлик "ÐÑ
од" пÑоизведен')697 # Шаг 2698 self.click_a('РегиÑÑÑаÑиÑ')699 self.loger_info('Шаг 2 Ðлик "РегиÑÑÑаÑиÑ" пÑоизведен')700 time.sleep(SLEEP_SHORT)701 # Шаг 3702 self.login('email', email)703 print('Шаг 3 Ðвод логина', email, 'пÑоизведен')704 # Шаг 4705 self.driver.find_element_by_css_selector('#register-email-password').send_keys(passw)706 # page.login('password', passw)707 self.loger_info('Шаг 4 Ðвод паÑÐ¾Ð»Ñ Ð¿Ñоизведен')708 time.sleep(SLEEP_SHORT)709 # Шаг 5710 self.driver.find_element_by_id('register-email-submit').click()711 self.loger_info('Шаг 5 Ðлик "ÐаÑегиÑÑÑиÑоваÑÑÑÑ" пÑоизведен')712 time.sleep(7)713 prof.click_f('Ðлик_ÐваÑаÑка_Ð', 5)714 self.loger_info('Шаг 6 Ðлик на аваÑаÑÐºÑ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ Ð¿Ñоизведен')715 self.waitForElementVisible('.//div[@class="profile-menu__name __username"]', 7)716 # ÐÑовеÑка авÑоÑизаÑии полÑзоваÑелÑ"717 resic = str(result.find_link("div", "profile-menu__name __username"))718 # email - пÑовеÑоÑное ÑловоÑоÑеÑание надпиÑи719 assert (email) in resic720 self.loger_info('ÐвÑоÑизаÑÐ¸Ñ Ð·Ð°ÑегиÑÑÑиÑованного полÑзоваÑÐµÐ»Ñ Ñ Ðµ-майлом ' + email + ' подÑвеÑждена')721 time.sleep(SLEEP_SHORT)722 def input_card(self, number, month, year, name_card, cvv):723 result = ResultPage(self.driver)724 self.driver.find_elements_by_xpath('.//input[@class="payment-cloudpayments__field textbox js-input"]')[725 0].send_keys(number)726 self.loger_info('Шаг 10 Ðвод номеÑа каÑÑÑ Ð¿Ñоизведен ' + number)727 time.sleep(3)728 self.driver.find_elements_by_xpath('.//select[@class="dropdown js-input"]')[0].click()729 time.sleep(1)730 self.driver.find_element_by_xpath('.//option[@value="%s"]' % month).click()731 self.loger_info('Ðвод меÑÑÑа каÑÑÑ Ð¿Ñоизведен')732 time.sleep(3)733 self.driver.find_elements_by_xpath('.//select[@class="dropdown js-input"]')[1].click()734 self.driver.find_element_by_xpath('.//option[@value="%s"]' % year).click()735 self.loger_info('Ðвод года каÑÑÑ Ð¿Ñоизведен')736 time.sleep(3)737 # ÐаполниÑÑ Ð¿Ð¾Ð»Ðµ "ÐÐ¼Ñ Ð´ÐµÑжаÑелÑ" - Ivanov Ivan738 self.driver.find_elements_by_xpath('.//input[@class="payment-cloudpayments__field textbox js-input"]')[739 1].send_keys(name_card)740 self.loger_info('Ðвод имени деÑжаÑÐµÐ»Ñ ÐºÐ°ÑÑÑ Ð¿Ñоизведен')741 time.sleep(3)742 # ÐаполниÑÑ Ð¿Ð¾Ð»Ðµ "CVV код" - 526743 self.driver.find_element_by_xpath(744 './/input[@class="payment-cloudpayments__field payment-cloudpayments__field_cvc textbox js-input"]').send_keys(745 cvv)746 self.loger_info('Ðвод CVV код каÑÑÑ Ð¿Ñоизведен')747 time.sleep(4)748 #СнÑÑÑ Ð³Ð°Ð»Ð¾ÑÐºÑ "СоÑ
ÑаниÑÑ Ð´Ð°Ð½Ð½Ñе каÑÑÑ"749 # self.driver.find_element_by_xpath('.//span[@class="toggle__label"]').click()750 # self.loger_info('СнÑÑие галоÑки в Ñек-бокÑе"СоÑ
ÑаниÑÑ Ð´Ð°Ð½Ð½Ñе каÑÑÑ" пÑоизведено')751 # ÐажаÑÑ ÐºÐ½Ð¾Ð¿ÐºÑ "ÐплаÑиÑÑ"clip-watch752 #self.driver.find_element_by_xpath('.//button[@class="payment-cloudpayments__pay button button_stretched js-buy-button"]').click()753 #self.loger_info('Ðлик "ÐплаÑиÑÑ" пÑоизведен')754 #time.sleep(1)755 # message = str(result.find_link("section", "tvz-alerts tvz-animation-fadeOut"))756 # self.loger_info('СообÑение Ð²Ð½Ð¸Ð·Ñ ÑоÑÐ¼Ñ Ð¾Ð¿Ð»Ð°ÑÑ:')757 # self.loger_info('message:' + message)758 def delete_mails(self, emailgo, passgo):759 # self.driver.get('https://mail.google.com')760 self.loger_info('Шаг 5 ÐеÑеÑ
од на gmail.com пÑоизведен')761 # self.login_google(emailgo, passgo)762 time.sleep(SLEEP_SHORT)763 # self.driver.get('https://mail.google.com/mail/u/0/#inbox')764 # Удаление пиÑÑма из поÑÑÑ765 self.click_xpath('.//div[@class="J-J5-Ji J-JN-M-I-Jm"]')766 # self.driver.find_element_by_id(':3d').click()767 self.loger_info('ÐоÑÑавлена галоÑка ÑÐµÐºÐ±Ð¾ÐºÑ - вÑÐ±Ð¾Ñ Ð¿Ð¸ÑÑма')768 self.click_xpath('//*[@id=":5"]/div/div[1]/div[1]/div/div/div[2]/div[3]')769 # self.click_xpath('.//div[@class="T-I J-J5-Ji nX T-I-ax7 T-I-Js-Gs mA"]')770 self.loger_info('Ðлик кнопки "УдалиÑÑ" пиÑÑмо на gmail.com пÑоизведен')771 time.sleep(SLEEP_SHORT)772 @property773 def consol_jenkins(self):774 print('ÐапÑÑк пÑовеÑки конÑоли')775 # p = subprocess.call('ffmpeg.exe -framerate 10 -f image2 -i "Frame%03d.jpg" -r 10 -s 620x380 Video.avi', shell=True)776 # options = webdriver.ChromeOptions()777 #self.driver = webdriver.Chrome("C:\chromedriver\chromedriver.exe", chrome_options=options)778 options.add_argument('--incognito') # ÐапÑÑк бÑаÑзеÑа в Ñежиме инкогниÑо779 # self.driver = webdriver.Chrome(options=options)780 #self.driver = webdriver.Chrome("C:\chromedriver\chromedriver.exe")781 self.driver.get("http://192.168.2.31:8080/jenkins/job/1_Regress/")782 self.driver.maximize_window()783 self.driver.implicitly_wait(10)784 page = MainPage(self.driver)785 result = ResultPage(self.driver)786 self.send_name('j_username', 'admin')787 self.send_name('j_password', 'admin')788 self.click_xpath('.//div[@class="Checkbox-indicator"]')789 self.click_name('Submit')790 self.driver.implicitly_wait(5)791 self.driver.find_elements_by_xpath('.//td[@class="build-row-cell"]')[0].click()792 self.click_a('ÐÑвод конÑоли')793 res = self.driver.find_element_by_xpath('.//pre[@class="console-output"]').text794 self.driver.close()795 return res796 def mail_send_web(self, login, passw):797 self.driver.execute_script("window.open('','_blank');")798 time.sleep(2)799 self.driver.switch_to.window(self.driver.window_handles[1])800 time.sleep(2)801 result = ResultPage(self.driver)802 self.driver.get("https://e.mail.ru/login")803 self.driver.maximize_window()804 self.driver.implicitly_wait(10)805 self.loger_info(' ÐеÑеÑ
од в mail пÑоизведен')806 time.sleep(2)807 #808 # # self.driver.find_element_by_name("Login").send_keys('testmailtvzavr15')809 self.driver.find_element_by_xpath('.//*[@id="root"]/div/div[3]/div/div/div/form/div[2]/div[2]/div[1]/div/div/div/div/div/div[1]')[0].click()810 self.driver.find_element_by_xpath('.//*[@id="root"]/div/div[3]/div/div/div/form/div[2]/div[2]/div[1]/div/div/div/div/div/div[1]').send_keys('testmailtvzavr15')811 time.sleep(2)812 #813 self.driver.find_element_by_xpath('.//span[@class="c01104 c0179 c01102 c0177"]').click() # Ðлик далее814 time.sleep(3)815 def scype_send_web(self, login, passw):816 self.driver.execute_script("window.open('','_blank');")817 time.sleep(2)818 self.driver.switch_to.window(self.driver.window_handles[1])819 time.sleep(2)820 result = ResultPage(self.driver)821 # options = webdriver.ChromeOptions()822 # options.add_argument("--disable-notifications")823 # options.add_argument('--incognito') # ÐапÑÑк бÑаÑзеÑа в Ñежиме инкогниÑо824 # self.driver = webdriver.Chrome(options=options)825 #self.driver = webdriver.Chrome("C:\chromedriver\chromedriver.exe")826 self.driver.get("https://web.skype.com/ru/")827 self.driver.maximize_window()828 self.driver.implicitly_wait(10)829 self.loger_info(' ÐеÑеÑ
од в Skype пÑоизведен')830 time.sleep(2)831 self.driver.find_element_by_name("loginfmt").send_keys('79776410337')832 time.sleep(2)833 self.driver.find_element_by_xpath('.//input[@id="idSIButton9"]').click() # Ðлик далее834 time.sleep(3)835 self.driver.find_element_by_name("passwd").send_keys('Aleh1260337')836 self.loger_info('Ðвод Skype паÑÐ¾Ð»Ñ Ð¿Ñоизведен')837 time.sleep(3)838 self.driver.find_element_by_xpath('.//input[@id="idSIButton9"]').click() # Ðлик вÑ
од839 self.loger_info('Ðлик ÐÑ
од пÑоизведен')840 time.sleep(3)841 self.driver.find_element_by_xpath('.//div[@id="rx-vlv-6"]').click() # Ðлик по диалогÑ842 self.loger_info('Шаг 100. ÐеÑеÑ
од в ÑÐ°Ñ ÐÐµÐ¿Ð»Ð¾Ð¹Ð¼ÐµÐ½Ñ Ð¿Ñоизведен')843 time.sleep(10)844 #self.driver.find_element_by_css_selector(".public-DraftStyleDefault-block").click() # Ðлик по Ð¿Ð¾Ð»Ñ Ð²Ð²Ð¾Ð´Ð°845 time.sleep(15)846 #print('ÑÑÑ2222')847 #time.sleep(2)848 # self.driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[1]/div/div/div/div/div[2]/div[3]').send_keys('text')849 # self.send_f('Ðвод_ÑообÑениÑ_Ñкайп', 'text', 15)850 # self.driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[1]/div/div/div/div/div[2]').send_keys('text')851 #self.driver.find_element_by_css_selector('[id="#.public-DraftStyleDefault-block"]').send_keys('text')852 #self.page.loger('ÑÑÑ')853 # self.click_xpath('//*[@id="swxContent1"]/swx-navigation/div/div/div/label/div/div/div[2]/div[2]/div/swx-button/button')854 # self.loger_info('ÐÑпÑавка ÑекÑÑа в ÑÐ°Ñ ÐÐµÐ¿Ð»Ð¾Ð¹Ð¼ÐµÐ½Ñ Ð¿Ñоизведена')855 # self.driver.close()856 # def delete_uzer(self, name): # ФУÐÐЦÐЯ УÐÐÐÐÐÐЯ ÐÐÐЬÐÐÐÐТÐÐЯ ÐÐ ÐÐÐÐÐÐÐ857 # self.driver.execute_script("window.open('','_blank');")858 # time.sleep(2)859 # self.driver.switch_to.window(self.driver.window_handles[1])860 # time.sleep(2)861 # self.driver.get("https://www.tvzavr.ru:8080/admin/")862 # time.sleep(2)863 # # 'ÐÑкÑÑÑие ÑÑÑаниÑÑ Ð°Ð´Ð¼Ð¸Ð½ÐºÐ¸864 # self.driver.maximize_window()865 # time.sleep(3)866 # self.driver.implicitly_wait(7)867 # self.driver.find_element_by_xpath(...
insta_bot.py
Source:insta_bot.py
...46 return arguments[0].scrollHeight;47 """, scrollBox)48 return scrollBox49 def dismiss_notNow(self):50 self.click_xpath("//button[contains(text(),'Not Now')]")51 def page_data(self, account, action):52 """self, account, action (2 = followers, 3 = following)"""53 self.driver.get(self.url + account)54 sleep(2)55 self.driver.find_element_by_xpath(56 f"//ul[not(ancestor::nav)]/li[{str(action)}]/a").click()57 scrollBox = self.scroll_box()58 links = scrollBox.find_elements_by_tag_name('a')59 names = [name.text for name in links if name.text != '']60 # close button61 self.driver.find_element_by_xpath(62 "//div[@role='dialog']/div[1]//button[1]").click()63 return names64 def click_xpath(self, path):65 sleep_rand_range(3, 5)66 btn = self.driver.find_elements_by_xpath(path)67 try:68 if len(btn) > 0:69 btn[0].click()70 except:71 btn = None72 return btn73 def follow(self, account):74 self.driver.get(self.url + account)75 return self.click_xpath("//button[contains(text(),'Follow')]")76 def like(self, account):77 self.driver.get(self.url + account)78 posts = self.driver.find_elements_by_xpath(79 "//a[starts-with(@href, '/p/')]")80 if(len(posts) > 0):81 sleep_rand_range(3, 5)82 if(len(posts) > 2):83 posts[choice(range(0, 3))].click() # image84 else:85 posts[0].click() # image86 lBtn = self.click_xpath(87 "//*[name()='svg'][@aria-label='Like']/..") # likeBtn88 cBtn = self.click_xpath(89 "//*[name()='svg'][@aria-label='Close']/..") # closeBtn90 if not (lBtn and cBtn):91 print("failed liking: " + account)92 def banner_on(self):93 opt = ["OK", "Report a Problem"]94 isOn = self.click_xpath(95 f"//button[contains(text(),'{opt[choice([0, 1])]}')]")96 if isOn:97 print(f"banner on")98 return isOn99 def un_follow(self, account):100 self.driver.get(self.url + account)101 if self.click_xpath("//span[@aria-label='Following']/../.."):102 if self.click_xpath("//button[contains(text(),'Unfollow')]"):103 return104 print("failed unfollowing: " + account)105 def scroll(self):106 if(choice([1, 2]) == 1):107 self.driver.get(self.url + "explore/")108 else:109 self.driver.get(self.url)110 # number of scolls to do111 numOf = randrange(15, 20)112 sleep_rand(2)113 for i in range(numOf):114 scrollAmount = randrange(600, 800)115 self.driver.execute_script(f"window.scrollBy(0,{scrollAmount})")116 sleep_rand_range(3, 5)
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!!