How to use find_element method in pom

Best Python code snippet using pom_python

personality_sri.py

Source:personality_sri.py Github

copy

Full Screen

...10dvr=webdriver.Chrome('./chromedriver')11url='https://www.saramin.co.kr/zf_user/auth?url=%2Fzf_user%2F'12dvr.get(url)13#로그인14com_btn=dvr.find_element(By.XPATH,'//*[@id="login_frm"]/div[2]/div[1]/ul[1]/li[2]/a')15id_box=dvr.find_element(By.CSS_SELECTOR,'#id')16pw_box=dvr.find_element(By.CSS_SELECTOR,'#password')17lgn_btn=dvr.find_element(By.CSS_SELECTOR,'#login_frm > div.login_page_wrap > div.login_input_wrap > div.login-form > button')18com_btn.click()19id_box.send_keys(id)20pw_box.send_keys(pw)21lgn_btn.click()22#인적성 홈 이동23dvr.get('https://www.saramin.co.kr/zf_user/memcom/preview/home')24#검사 등록 버튼 클릭25dvr.find_element(By.CSS_SELECTOR,'#preview_home_area > div.wrap_top_human > div.area_right > div.area_card.newly_card > div > button').click()26# 인적성 종류 선택27dvr.find_element(By.CSS_SELECTOR,'#exam_category').click()28# 사람인hr 연구소 인적성검사 선택29dvr.find_element(By.XPATH, '//*[@id="exam_category"]/option[10]').click()30# 인적성검사명31rec_nm=dvr.find_element(By.CSS_SELECTOR, '#exam_title')32# 월+일 4자로 보여주기 (ex. 0628)33# a=문자형(오늘.월).2자리 될때까지 0으로 채우기+문자형(오늘, 일).2자리 될때까지 0으로 채우기34a=(str(datetime.today().month).zfill(2)+str(datetime.today().day).zfill(2))35#제목: a+제목+i36rec_nm.send_keys(a+' 사람인 인적성 테스트 ')37#안내 방법38dvr.find_element(By.CSS_SELECTOR, '#auto_alarm_ck_not_send').send_keys(Keys.SPACE)39# 응시완료 알림 설정40dvr.find_element(By.CSS_SELECTOR, '#complete_noti_type_none').send_keys(Keys.SPACE)41# 등록 버튼 클릭42dvr.find_element(By.CSS_SELECTOR, '#add_exam_button').click()43dvr.switch_to.alert.accept()44#상품 미보유 체크:일단 모달 레이어 제목을 가져와보고, 실패하면 0으로 넣기45try: product = dvr.find_element(By.CSS_SELECTOR, '#preview_no_have_product_layer > div.modalTit > h3')46except:product=047try: add = dvr.find_element(By.CSS_SELECTOR, '#add_preview_user_layer > div.modalTit > h3')48except:add=049# 변수에 들어있는게 0이 아니면 (제목이 가져와지면) 그에 맞는 행동을 하게끔50if (add!=0):51 # 상품이 없을 경우에만 구매를 하는 프로세스가 추가되고, 응시자추가는 동일하게 하기 때문에 응시자 추가는 if문 밖에 짜고 여기선 패스52 pass53elif (product!=0):54 #모달에서 구매 버튼 누르기55 dvr.find_element(By.CSS_SELECTOR, '#preview_no_have_product_layer > div.modalBtn.box_verify_btn > button').click()56 #결제창이 새창으로 열리니까 그 창으로 포커스 바꾸기57 dvr.switch_to.window(dvr.window_handles[1])58 #포인트 전액사용 버튼 누르기59 dvr.find_element(By.CSS_SELECTOR, '#content > div.product_order > div > div.apply_discount > dl:nth-child(5) > dd:nth-child(2) > button').click()60 61 # 결제동의 체크박스 누르기62 dvr.find_element(By.CSS_SELECTOR, '#isPaymentAgreement').send_keys(Keys.SPACE)63 # 결제하기 누르기64 dvr.find_element(By.CSS_SELECTOR, '#makePayment').click()65 time.sleep(5)66 # 인적성 관리 페이지 열기67 dvr.get('https://www.saramin.co.kr/zf_user/memcom/preview/main')68 # 응시자 추가 버튼 누르기69 dvr.find_element(By.CSS_SELECTOR, '#preview_list_area > div:nth-child(1) > div:nth-child(3) > button').click()70else:print('something wrong')71#응시자 추가72#수동입력 클릭73dvr.find_element(By.CSS_SELECTOR, '#direct_member').click()74#이름, 메일, 번호 입력75dvr.find_element(By.CSS_SELECTOR, '#add_direct_user_list_div > tr:nth-child(1) > td:nth-child(2) > input').send_keys('test')76dvr.find_element(By.CSS_SELECTOR, '#add_direct_user_list_div > tr:nth-child(1) > td:nth-child(3) > input').send_keys('test@saramin.co.kr')77dvr.find_element(By.CSS_SELECTOR, '#add_direct_user_list_div > tr:nth-child(1) > td:nth-child(4) > input').send_keys('010-0000-0000')78#응시자 추가 버튼 클릭79dvr.find_element(By.CSS_SELECTOR, '#btn_add_user').click()80time.sleep(1)81dvr.switch_to.alert.accept()82#응시 id, 비번 따오기83# 인적성 관리 상세페이지 열어야함 >> 인적성 관리 리스트에서 가장 최근 검사로 갈 수 있는 웹 엘리먼트 선택 > 해당 엘리먼트의 href 속성의 값을 가져오고(Str형), 끝에서 6자리 슬라이스84href=dvr.find_element(By.CSS_SELECTOR, '#preview_list_area > div:nth-child(1) > div.item.left > div > div.title > h2 > span > a').get_attribute('href')85exam_seq=href[-6:]86url2='https://www.saramin.co.kr/zf_user/memcom/preview/user-list?page_count=5&siat_exam_seq='87dvr.get(url2+exam_seq)88# 검사 id, 비번 저장89exam_id=dvr.find_element(By.CSS_SELECTOR, '#preview_user_list_area > div.tblSticky > table > tbody > tr > td:nth-child(5)').text90exam_cert=dvr.find_element(By.CSS_SELECTOR, '#preview_user_list_area > div.tblSticky > table > tbody > tr > td:nth-child(6)').text91#--------------------------응시자 등록 끝---------------------------------------92# siat 페이지 이동+로그인93dvr.get('https://www.saramin.co.kr/zf_user/siat')94dvr.find_element(By.CSS_SELECTOR, '#auth_id').send_keys(exam_id)95dvr.find_element(By.CSS_SELECTOR, '#auth_pw').send_keys(exam_cert)96dvr.find_element(By.CSS_SELECTOR, '#authForm > div.box_btn > button').click()97time.sleep(1)98dvr.find_element(By.CSS_SELECTOR, '#career_type_0').send_keys(Keys.SPACE)99dvr.find_element(By.CSS_SELECTOR, '#job').click()100dvr.find_element(By.XPATH, '//*[@id="job"]/option[2]').click()101dvr.find_element(By.CSS_SELECTOR, '#agree_chk').send_keys(Keys.SPACE)102dvr.find_element(By.CSS_SELECTOR, '#exam_next').click()103dvr.find_element(By.CSS_SELECTOR, '#start_exam').click()104# 페이지 하나씩 넘기기105# for i in range(1,10) :106# dvr.find_element(By.CSS_SELECTOR, '#next_exam_button').click()107dvr.find_element(By.CSS_SELECTOR, '#immediately_move_span_60 > button').click()108time.sleep(0.5)109dvr.find_element(By.CSS_SELECTOR, '#complete_exam_button').click()110dvr.switch_to.alert.accept()111#-------인성검사 시작---------112dvr.find_element(By.CSS_SELECTOR, '#start_exam').click()113# 전부 '아니다' 체크하도록 만듦114# 각 버튼의 아이디는 'answer_expl_'+번호이며, +4되는 패턴 >> a 초기값 넣고 4씩 늘려가면서 찍도록115a=2719116for i in range(1,16):117 118 for i in range(1,11):119 sel='answer_expl_'+str(a)120 dvr.find_element(By.ID, sel).send_keys(Keys.SPACE)121 a+=4122 # 중간중간 문제가 삭제되었는지 누락된 번호가 있음 >> 한 번 더 업데이트해서 다음 문제 누르도록123 if a==3199:124 a+=4125 elif a==3275:126 a+=4127 128 elif a==3295:129 a+=4130 elif a==3303:131 a+=4 132 133 time.sleep(0.3)134 # a값을 체크해서 마지막 문제가 체크되었을지 확인(a가 마지막 문제 '아니오' 버튼의 번호보다 작은지 확인) > 체크가 되었다면 제출 버튼 클릭, 아니라면 다음 버튼 클릭135 if a<3331:136 dvr.find_element(By.CSS_SELECTOR, '#next_exam_button').click()137 try:138 dvr.switch_to.alert.accept()139 dvr.find_element(By.CSS_SELECTOR, '#next_exam_button').click()140 except:pass141 142 else: dvr.find_element(By.CSS_SELECTOR, '#complete_exam_button').click() 143 time.sleep(0.3)...

Full Screen

Full Screen

test_endtoend.py

Source:test_endtoend.py Github

copy

Full Screen

...25 #connect to web application26 self.driver.get("http://localhost:3000/")27 self.driver.set_window_size(1920, 1040)28 #Sign in29 self.driver.find_element(By.CSS_SELECTOR, ".text-center").click()30 self.driver.find_element(By.NAME, "email").click()31 self.driver.find_element(By.NAME, "email").send_keys("ryangreen@gmail.com")32 self.driver.find_element(By.NAME, "password").click()33 self.driver.find_element(By.CSS_SELECTOR, "div:nth-child(2) > div:nth-child(1)").click()34 self.driver.find_element(By.NAME, "password").send_keys("testing123")35 self.driver.find_element(By.CSS_SELECTOR, ".btn:nth-child(5)").click()36 self.driver.implicitly_wait(2)37 #Add horse38 self.driver.find_element(By.LINK_TEXT, "Dashboard").click()39 self.driver.find_element(By.LINK_TEXT, "Add Horses").click()40 self.driver.find_element(By.NAME, "horse_name").click()41 self.driver.find_element(By.NAME, "horse_name").send_keys("test horse")42 self.driver.find_element(By.NAME, "passport_no").click()43 self.driver.find_element(By.NAME, "passport_no").send_keys("122223333444444")44 self.driver.find_element(By.NAME, "weight_kg").click()45 self.driver.find_element(By.NAME, "weight_kg").send_keys("200")46 self.driver.find_element(By.NAME, "height_cm").click()47 self.driver.find_element(By.NAME, "height_cm").send_keys("180")48 self.driver.find_element(By.NAME, "colour").click()49 self.driver.find_element(By.NAME, "colour").send_keys("test")50 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(3) > .form-group:nth-child(2) > .form-control").click()51 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(3) > .form-group:nth-child(2) > .form-control").send_keys("test")52 self.driver.find_element(By.NAME, "horse_breed").click()53 self.driver.find_element(By.NAME, "horse_breed").send_keys("test")54 self.driver.find_element(By.NAME, "client_name").click()55 self.driver.find_element(By.NAME, "client_name").send_keys("test")56 self.driver.find_element(By.LINK_TEXT, "Add Horse").click()57 #make prediction58 self.driver.find_element(By.LINK_TEXT, "Home").click()59 element = self.driver.find_element(By.LINK_TEXT, "Home")60 actions = ActionChains(self.driver)61 actions.move_to_element(element).perform()62 element = self.driver.find_element(By.CSS_SELECTOR, "body")63 actions = ActionChains(self.driver)64 self.driver.find_element(By.NAME, "horse_id").click()65 dropdown = self.driver.find_element(By.NAME, "horse_id")66 dropdown.find_element(By.XPATH, "option['test horse // 122223333444444 // test']").click()67 self.driver.find_element(By.CSS_SELECTOR, ".btn-success").click()68 element = self.driver.find_element(By.CSS_SELECTOR, ".btn-success")69 actions = ActionChains(self.driver)70 actions.move_to_element(element).perform()71 self.driver.find_element(By.CSS_SELECTOR, ".btn-warning").click()72 #see individual horse prediction & download csv73 self.driver.find_element(By.LINK_TEXT, "Dashboard").click()74 self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) > td:nth-child(11) > .btn").click()75 self.driver.find_element(By.LINK_TEXT, "Download me").click()76 self.driver.find_element(By.CSS_SELECTOR, ".btn-default").click()77 element = self.driver.find_element(By.CSS_SELECTOR, ".btn-default")78 actions = ActionChains(self.driver)79 actions.move_to_element(element).perform()80 #see the account prediction history81 self.driver.find_element(By.LINK_TEXT, "See Prediction History").click()82 #edit horse83 self.driver.find_element(By.LINK_TEXT, "Dashboard").click()84 self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) > td:nth-child(12) > .btn").click()85 self.driver.find_element(By.CSS_SELECTOR, ".userInfo > div").click()86 self.driver.find_element(By.NAME, "horse_name").send_keys("edit")87 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(1)").click()88 self.driver.find_element(By.NAME, "passport_no").send_keys("444444444444444")89 self.driver.find_element(By.CSS_SELECTOR, ".container > div > .container").click()90 self.driver.find_element(By.NAME, "weight_kg").send_keys("300")91 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(2)").click()92 self.driver.find_element(By.NAME, "height_cm").send_keys("177")93 self.driver.find_element(By.CSS_SELECTOR, ".container > div > .container").click()94 self.driver.find_element(By.NAME, "colour").send_keys("edit")95 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(3)").click()96 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(3) > .form-group:nth-child(2) > .form-control").send_keys("edit")97 self.driver.find_element(By.CSS_SELECTOR, ".container > div > .container").click()98 self.driver.find_element(By.NAME, "horse_breed").send_keys("edit")99 self.driver.find_element(By.CSS_SELECTOR, ".form-row:nth-child(4)").click()100 self.driver.find_element(By.NAME, "client_name").send_keys("edit")101 self.driver.find_element(By.CSS_SELECTOR, ".btn-success").click()102 #change status of horse x3103 self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) > td:nth-child(14) > .btn").click()104 self.driver.find_element(By.CSS_SELECTOR, ".btn:nth-child(2)").click()105 self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) > td:nth-child(14) > .btn").click()106 self.driver.find_element(By.CSS_SELECTOR, ".btn:nth-child(3)").click()107 #delete horse108 self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) > td:nth-child(14) > .btn").click()109 self.driver.find_element(By.CSS_SELECTOR, ".btn:nth-child(4)").click()110 self.driver.find_element(By.CSS_SELECTOR, "tr:nth-child(4) > td:nth-child(13) > .btn").click()111 #logout112 self.driver.find_element(By.LINK_TEXT, "Logout").click()...

Full Screen

Full Screen

AddCustomePage.py

Source:AddCustomePage.py Github

copy

Full Screen

...30 __SuccessMessage_xpath = (By.XPATH, "//div[@class='alert alert-success alert-dismissable']")31 def __init__(self, driver):32 super().__init__(driver)33 def clickCustomers(self):34 self.driver.find_element(*addCustomer.__link_customer_xpath).click()35 def clickCustomersMenu(self):36 self.elementToClickable(self.__link_customer_menu_xpath)37 self.driver.find_element(*addCustomer.__link_customer_menu_xpath).click()38 def addNew(self):39 self.driver.find_element(*addCustomer.__Add_new_xpath).click()40 def setEmail(self, email):41 self.driver.find_element(*addCustomer.__Email_box_css).clear()42 self.driver.find_element(*addCustomer.__Email_box_css).send_keys(email)43 def setPassword(self, password):44 self.driver.find_element(*addCustomer.__Password_box_id).clear()45 self.driver.find_element(*addCustomer.__Password_box_id).send_keys(password)46 def setFirstName(self, FirstName):47 self.driver.find_element(*addCustomer.__FirstName_box_css).clear()48 self.driver.find_element(*addCustomer.__FirstName_box_css).send_keys(FirstName)49 def setLastName(self, LastName):50 self.driver.find_element(*addCustomer.__LastName_box_css).clear()51 self.driver.find_element(*addCustomer.__LastName_box_css).send_keys(LastName)52 def setDOB(self, dob):53 self.driver.find_element(*addCustomer.__DOB_box_id).clear()54 self.driver.find_element(*addCustomer.__DOB_box_id).send_keys(dob)55 def setCompany(self, company):56 self.driver.find_element(*addCustomer.__Company_box_id).clear()57 self.driver.find_element(*addCustomer.__Company_box_id).send_keys(company)58 def clickTaxExempt(self):59 self.driver.find_element(*addCustomer.__tax_exempt_click_id).click()60 def setCustomerRoles(self, role):61 self.driver.find_element(*addCustomer.__customerRole_xpath).click()62 if role == "Registered":63 self.elementToClickable(self.__Registered_xpath)64 self.listItem = self.driver.find_element(*addCustomer.__Registered_xpath)65 elif role == "Administrator":66 self.elementToClickable(self.__Administrator_xpath)67 self.listItem = self.driver.find_element(*addCustomer.__Administrator_xpath)68 elif role == "Guests":69 self.driver.find_element_by_xpath("//*[@id='SelectedCustomerRoleIds_taglist']/li/span[2]").click()70 self.listItem = self.driver.find_element(*addCustomer.__Guest_xpath)71 elif role == "Vendors":72 self.listItem = self.driver.find_element(*addCustomer.__Vendors_xpath)73 self.driver.execute_script("arguments[0].click();", self.listItem)74 def setManagerVendor(self, value):75 element = self.driver.find_element(*addCustomer.__vendor_box_css)76 drp = Select(element)77 drp.select_by_visible_text(value)78 def setGender(self, gender):79 if gender == "Male":80 self.driver.find_element(*addCustomer.__Gender_Male_id).click()81 elif gender == "Female":82 self.driver.find_element(*addCustomer.__Gender_Female_id).click()83 def setAdminComment(self, comment):84 self.driver.find_element(*addCustomer.__Admin_comment_css).send_keys(comment)85 def clickSave(self):86 self.driver.find_element(*addCustomer.__Save_xpath).click()87 def verifyAddCustomerTest(self):...

Full Screen

Full Screen

RegisterPage.py

Source:RegisterPage.py Github

copy

Full Screen

...31 # 调用page中的_open打开连接32 self._open(self.base_url)33 # 输入用户名:调用send_keys对象,输入用户名34 def input_danweiname(self, danweiname):35 # self.find_element(*self.username_loc).clear()36 self.find_element(*self.danweiname_loc).send_keys(str(danweiname))37 # def select_province(self, province):38 # # self.find_element(*self.username_loc).clear()39 # self.find_element(*self.province_loc).click()40 # self.find_element(*(By.XPATH, self.province2_loc_value+str(province)+']')).click()41 #42 # def select_city(self, city):43 # # self.find_element(*self.username_loc).clear()44 # self.find_element(*self.city_loc).click()45 # self.find_element(*(By.XPATH, self.city2_loc_value+str(city)+']')).click()46 #47 # def select_area(self, area):48 # # self.find_element(*self.username_loc).clear()49 # self.find_element(*self.area_loc).click()50 # self.find_element(*(By.XPATH, self.area2_loc_value+str(area)+']')).click()51 #52 # def input_email(self, email):53 # # self.find_element(*self.username_loc).clear()54 # self.find_element(*self.email_loc).send_keys(str(email))55 #56 # def input_username(self, username):57 # # self.find_element(*self.username_loc).clear()58 # self.find_element(*self.username_loc).send_keys(str(username))59 #60 # def input_phonenum(self, phonenum):61 # # self.find_element(*self.username_loc).clear()62 # self.find_element(*self.phonenum_loc).send_keys(str(phonenum))63 #64 # def input_password1(self, password1):65 # # self.find_element(*self.username_loc).clear()66 # self.find_element(*self.password1_loc).send_keys(str(password1))67 #68 # def input_password2(self, password2):69 # # self.find_element(*self.username_loc).clear()70 # self.find_element(*self.password2_loc).send_keys(str(password2))71 #72 # def click_registerbutton(self):73 # # self.find_element(*self.username_loc).clear()74 # self.find_element(*self.registerbutton_loc).click()75 #76 # def is_sussess(self):77 # actualval = self.find_element(*self.assert_loc).text78 # return actualval79 # # 用户名或密码不合理是Tip框内容展示80 # def show_span(self):81 # return self.find_element(*self.span_loc).text82 #83 # # 切换登录模式为动态密码登录(IE下有效)84 # def swich_DynPw(self):85 # self.find_element(*self.dynpw_loc).click()86 #87 # # 登录成功页面中的用户ID查找88 # def show_userid(self):...

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 pom 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