Best Python code snippet using robotframework-appiumlibrary_python
tasks.py
Source:tasks.py
...30 for i in table:31 for row_index in range (1,10):32 for column_index in range (1,4):33 if row_index!=9:34 browser_lib.scroll_element_into_view('''//*[@id="agency-tiles-widget"]/div/div[{0}]/div[{1}]/div/div/div/div[1]/a/span[1]'''.format(row_index,column_index))35 time.sleep(10)36 # get agency name from the URL37 agency= browser_lib.get_text('''//*[@id="agency-tiles-widget"]/div/div[{0}]/div[{1}]/div/div/div/div[1]/a/span[1]'''.format(row_index,column_index))38 # match excel agency name with the browser agency name39 if str(i['Agencies Name'])==str(agency):40 browser_lib.click_element('''//*[@id="agency-tiles-widget"]/div/div[{0}]/div[{1}]/div/div/div/div[1]/a/span[1]'''.format(row_index,column_index))41 # GO to agency URL Page42 url_list =go_to_agency_page(str(agency),path_to_file)43 browser_lib.scroll_element_into_view('''//*[@class="navbar-brand trend_sans_oneregular"]''')44 time.sleep(10)45 browser_lib.click_element('''//*[@class="navbar-brand trend_sans_oneregular"]''')46 time.sleep(10)47 browser_lib.scroll_element_into_view('//a[@href="#home-dive-in"]')48 time.sleep(10)49 browser_lib.click_link('//a[@href="#home-dive-in"]')50 time.sleep(10)51 else:52 print("no data found")53 continue54 return url_list55 print("end of write_agencies_data_to_excel")56def download_wait(file_path):57 seconds = 058 dl_wait = True59 while dl_wait and seconds < 40:60 time.sleep(1)61 dl_wait = False62 if os.path.exists(file_path):63 dl_wait = True64 seconds += 165 return seconds66def download_pdf_file(url_list):67 url_list = set(url_list)68 # convert the set to the list69 url_list = (list(url_list))70 print(url_list)71 72 browser_lib.open_available_browser("https://google.com/")73 74 user_name =os.environ['USERPROFILE']75 output_dir= user_name+"\\RPA Challange Assignment\\Output_Files"76 77 if not os.path.exists(output_dir):78 os.makedirs(output_dir)79 download_dir =os.environ['USERPROFILE'] + '\Downloads'80 81 file_source = download_dir82 file_destination = output_dir+"\\"83 for i in url_list:84 pdf_name = i.split("/")85 file_source = download_dir+'\\'+pdf_name[-1]+".pdf"86 browser_lib.go_to(i)87 browser_lib.wait_until_element_is_visible('''//a[@href="#"]''')88 browser_lib.click_link('''//a[@href="#"]''')89 download_wait(file_source)90 print(file_source)91 time.sleep(20)92 if os.path.exists(file_source):93 if not os.path.exists(file_destination+"\\"+pdf_name[-1]+".pdf"):94 shutil.move(file_source , file_destination)95 else:96 print("no file exist")97 browser_lib.close_browser 98def extract_data_from_table(path_to_file,column,row):99 print("start of extract_data_from_table")100 excel_obj.open_workbook(path_to_file)101 column_count = browser_lib.get_element_count(column)102 # get the table headers103 for c in range (1,column_count+1):104 column_headers = browser_lib.get_text('''//*[@id="investments-table-object_wrapper"]/div[3]/div[1]/div/table/thead/tr[2]/th[{}]'''.format(c))105 excel_obj.set_cell_value(1,c,column_headers)106 excel_obj.save_workbook(path_to_file)107 108 url_list = []109 110 row_count = browser_lib.get_element_count(row)111 112 browser_lib.scroll_element_into_view('''//*[@id="investments-table-object_wrapper"]/div[3]''')113 114 for j in range (1,column_count+1):115 for i in range (1,row_count+1):116 text = browser_lib.get_text('''//*[@id="investments-table-object"]/tbody/tr[{0}]/td[{1}]'''.format(i,j))117 element_attribute = browser_lib.get_element_attribute('''//*[@id="investments-table-object"]/tbody/tr[{0}]/td[1]/a'''.format(j),"href")118 if type(element_attribute) == str:119 url_list.append(element_attribute) if element_attribute not in url_list else url_list120 url_list.append(element_attribute)121 excel_obj.set_cell_value(i+1,j,text)122 excel_obj.save_workbook(path_to_file)123 124 excel_obj.close_workbook()125 126 print("start of extract_data_from_table")127 return url_list128def go_to_agency_page(agency,path_to_file):129 print("end of go_to_agency_page")130 time.sleep(5)131 browser_lib.scroll_element_into_view('''//a[@href="#read-more-row-2"]''')132 time.sleep(10)133 browser_lib.click_link('''//a[@href="#read-more-row-2"]''')134 time.sleep(20)135 browser_lib.scroll_element_into_view('''//select[@name="investments-table-object_length"]''')136 time.sleep(20)137 browser_lib.select_from_list_by_label('''//select[@name="investments-table-object_length"]''','All')138 time.sleep(5)139 # extract headers140 browser_lib.scroll_element_into_view('''//*[@id="investments-table-object_wrapper"]/div[3]/div[1]/div/table/thead/tr[2]/th[1]''')141 time.sleep(5)142 column = '''//*[@id="investments-table-object_wrapper"]/div[3]/div[1]/div/table/thead/tr[2]/th'''143 row = '''//*[@id="investments-table-object"]/tbody/tr'''144 145 excel_obj.open_workbook(path_to_file)146 excel_obj.create_worksheet(agency)147 excel_obj.save_workbook(path_to_file)148 excel_obj.close_workbook()149 url_list =extract_data_from_table(path_to_file,column,row)150 print("end of go_to_agency_page")151 return url_list152 153# Define a main() function that calls the other functions in order:154def main():155 agency_title_widget ="agency-tiles-container"156 # cur_dir = str(os.getcwd())157 user_name =os.environ['USERPROFILE']158 output_dir= user_name+"\\RPA Challange Assignment\\Output_Files"159 160 if not os.path.exists(output_dir):161 os.makedirs(output_dir)162 path_to_file = str(output_dir)+"\\"+"Output File.xlsx"163 if os.path.exists(path_to_file):164 os.remove(path_to_file)165 else:166 print("file not exists")167 168 169 try:170 create_excel_file(path_to_file)171 open_the_website("https://itdashboard.gov/")172 browser_lib.maximize_browser_window()173 browser_lib.click_link('//a[@href="#home-dive-in"]')174 browser_title = browser_lib.get_window_titles()175 print(browser_title)176 browser_lib.scroll_element_into_view('''//*[@id="agency-tiles-container"]''')177 time.sleep(15)178 web_elements = browser_lib.get_text('''//*[@id="agency-tiles-container"]''')179 str_list = web_elements.split("view")180 str_list = [x.strip() for x in str_list if x.strip()]181 excel_obj.open_workbook(path_to_file)182 counter = 2183 for items in str_list:184 text = items.split('\n')185 agency_name = text[0]186 amount = text[2]187 excel_obj.set_worksheet_value(counter,1,agency_name)188 excel_obj.set_worksheet_value(counter ,2 ,amount)189 counter=counter+1190 excel_obj.save_workbook(path_to_file)...
loginPage.py
Source:loginPage.py
...20 register_email_field = self.browser.find_element(*LoginPageLocators.REGISTER_EMAIL_FIELD)21 register_password_field = self.browser.find_element(*LoginPageLocators.REGISTER_PASSWORD_FIELD)22 register_confirm_password_field = self.browser.find_element(*LoginPageLocators.REGISTER_CONFIRM_PASSWORD_FIELD)23 registration_submit_button = self.browser.find_element(*LoginPageLocators.REGISTER_SUBMIT_BUTTON)24 scroll_element_into_view(self.browser, register_email_field)25 register_email_field.send_keys(email)26 scroll_element_into_view(self.browser, register_password_field)27 register_password_field.send_keys(password)28 scroll_element_into_view(self.browser, register_confirm_password_field)29 register_confirm_password_field.send_keys(password)30 time.sleep(1)31 scroll_element_into_view(self.browser, registration_submit_button)...
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!!