Best Python code snippet using lettuce_webdriver_python
Main.py
Source:Main.py
...6from selenium.common.exceptions import NoSuchElementException7from config import DRIVER_PATH, USERNAME, PASSWORD, PHONE_NUMBER8import time9from datetime import date10def click_by_id(id):11 ele = driver.find_element_by_id(id)12 if not ele.is_selected():13 ele.click()14 return ele15def click_by_name(name):16 ele = driver.find_element_by_name(name)17 if not ele.is_selected():18 ele.click()19 return ele20def send_input(ele, input):21 ele.send_keys(input)22driver = webdriver.Chrome(executable_path=DRIVER_PATH)23driver.get("https://itsapps2.gmu.edu/symptom/Account/Login/")24# Click 'LOGIN WITH MASON NETID' button25click_by_id("gmulogin")26# Click field and enter username27ele = click_by_id("username")28send_input(ele, USERNAME)29# Click field and enter password30ele = click_by_id("password")31send_input(ele, PASSWORD)32# Click login33click_by_name("_eventId_proceed")34# -------------------------------DUO Authentication---------------------------------35frame = driver.find_element_by_id("duo_iframe")36driver.switch_to.frame(frame)37# Click remember for 14 days if not already selected38remember_14_days_ele = driver.find_element_by_xpath("/html/body/div/div/div[1]/div/form/div[2]/div/label/input")39if not remember_14_days_ele.is_selected():40 remember_14_days_ele.click()41# click passcode button42click_by_id("passcode")43# Enter 2SA passcode44while True:45 time.sleep(.5)46 duo_auth_passcode = input("Enter DUO Passcode: ")47 passcode_text_field_ele = driver.find_element_by_class_name("passcode-input")48 passcode_text_field_ele.click()49 passcode_text_field_ele.clear()50 passcode_text_field_ele.send_keys(duo_auth_passcode)51 click_by_id("passcode")52 53 time.sleep(.5)54 # If error doesn't exist hence NoSuchElementException then break out of loop55 try:56 driver.find_element_by_xpath('/html/body/div/div/div[4]/div/div[2]')57 58 # Untested - may print when not supposed to59 print("**Wrong Passcode**")60 print("May have to refresh code on DUO app")61 except NoSuchElementException:62 break63time.sleep(.5)64# Leave iframe65driver.switch_to.default_content()66# Start Health Risk Assessment button67start_assessment_ele = driver.find_element_by_class_name("input-group")68start_assessment_ele.click()69# --------------------------- Screening Portion ---------------------------70# Do you currently have any of the following conditions that are NOT explained by seasonal 71# allergies, flu, or another health condition?72click_by_id("rb_q_97_c2")73# Have you tested positive for COVID-19 in the last 10 days?74click_by_id("rb_q_98_c2")75# Have you had any of the following symptoms in the last 24 hours 76# that are not explained by seasonal allergies or another health condition?77click_by_id("rb_q_100_c2")78# In the last 14 days, have you been in close contact (less than 6 feet for 15 minutes or more) with79# ⢠Someone 2 days before or 10 days after they tested positive or were diagnosed with COVID-19, or80# ⢠Someone who had/has COVID-19 symptoms and is currently waiting for COVID-19 test results?81click_by_id("rb_q_103_c2")82# Are you fully vaccinated â received the second dose of Pfizer, Moderna vaccine, one dose of J&J vaccine, 83# or World Health Organization (WHO) authorized vaccine more than 14 days ago?84click_by_id("rb_q_104_c1")85# Are you planning to come to campus or participate in an in person Mason activity today?86click_by_id("rb_q_131_c1")87# Have you been on a Mason campus/facility or participated in a Mason sponsored/associated activity today or in the past 14 days?88click_by_id("rb_q_101_c1")89# Click Calendar button and input in date90ele = click_by_id("q_102")91today = date.today()92send_input(ele, today.strftime("%m%d"))93# Are you a student living on campus? Residential students answer yes even if you are not currently on campus.94click_by_id("rb_q_105_c1")95# Have you arrived from traveling outside the United States in the last 10 days? 96click_by_id("rb_q_106_c2")97# Phone Number98phone_ele = click_by_id("q_109")99phone_ele.clear()100send_input(phone_ele, PHONE_NUMBER)101 102# Do you consent and authorize George Mason University (GMU) to conduct collection, 103# testing and analysis of samples from you for the purpose of an approved Coronavirus (COVID-19) test?104click_by_id("rb_q_128_c1")105driver.find_elements_by_xpath("/html/body/div[1]/div/form/div/div[18]/div/input")[0].click()106# Closes the browser...
home_page.py
Source:home_page.py
...10 self.click_by_xpath(self.locator.backButton_bang)11 def click_back_eng(self):12 self.click_by_xpath(self.locator.backButton_eng)13 def click_profile_icon(self):14 self.click_by_id(self.locator.profileBtn)15 def click_post_btn(self):16 sleep(3)17 self.click_by_id(self.locator.postBtn)18 time.sleep(3)19 def close_intro(self):20 try:21 sleep(3)22 intro = self.driver.find_element_by_id(self.locator.intro_close_btn)23 sleep(1)24 intro.click()25 except Exception as e:26 print(e)27 def login(self):28 self.close_intro()29 self.click_profile_icon()30 self.click_by_id(self.locator.sign_in_email_btn)31 self.click_by_id(self.locator.emailField)32 self.send_data(self.locator.emailText, self.locator.emailField)33 self.click_by_id(self.locator.passwordField)34 self.send_data(self.locator.passwordText, self.locator.passwordField)35 self.click_by_id(self.locator.loginBtn)36 sleep(1)37 def click_my_ads(self):38 self.click_by_id(self.locator.myAds)39 def click_my_membership(self):40 self.click_by_id(self.locator.myMembership)41 def click_favorites(self):42 self.click_by_id(self.locator.favorites)43 def click_my_profile(self):44 self.click_by_id(self.locator.myProfile)45 def click_search_icon(self):46 self.click_by_id(self.locator.search_icon)47 def click_back_btn(self):48 self.click_by_class_name(self.locator.backButton_bang)49 def search_item(self):50 self.click_search_icon()51 self.click_by_id(self.locator.searchBox)52 sleep(1)53 self.click_by_id(self.locator.editSearchField)54 # self.driver.press_keycode(74)55 self.send_data('Mobile', self.locator.editSearchField)56 sleep(20)57 # self.driver.press_keycode(84)58 # sleep(10)59 def logout(self):60 self.login()61 self.click_by_id(self.locator.logoutBtn)62 time.sleep(2)63 def click_first_product(self):64 sleep(5)65 self.click_by_id(self.locator.first_product)66 sleep(4)67 def tap_settings(self):68 self.click_by_id(self.locator.gear_icon)69 time.sleep(3)70 def tap_english(self):71 self.click_by_xpath(self.locator.english_language)72 sleep(3)73 def switch_language_to_english(self):74 """It will change whole app language to English"""75 self.tap_settings()76 self.tap_english()77 def click_home(self):78 """clicks the home button"""79 self.click_by_id(self.locator.home_btn)80 def click_favorite_icon(self):81 """clicks favorite icon for a item"""82 self.click_by_id(self.locator.favorite_icon)83 def click_favorite_for_an_ad(self):84 """click favorite icon for a item"""85 self.click_home()86 self.click_first_product()87 self.click_favorite_icon()88 def click_category_btn(self):89 """clicks category btn"""90 self.click_by_id(self.locator.category_btn)91 def click_on_jobs(self):92 """clicks jobs"""93 self.click_by_xpath(self.locator.jobs_link)94 def click_job_search_field(self):95 """clicks on job search field"""96 self.click_by_id(self.locator.job_search_field)97 def click_on_search_btn(self):98 """clicks on job search button"""99 self.click_by_id(self.locator.search_btn)100 def set_data_on_job_search_field(self, data):101 """set data on search field"""...
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!!