def check_for_error(browser, abstract, document, alt=None): error_message = locate_element_by_class_name( browser, abstract.county.classes["Error Message"], "search error message", document=document, quick=True) if error_message is not None: print( f'Located an error during processing of {document.extrapolate_value()}...' ) if error_message.text.startswith( abstract.county.messages["Error Message"]): print( f'An error occurred while handling document located at ' f'{document.extrapolate_value()}, refreshing the page to try again.' ) browser.refresh() naptime() return abstract.county.messages["Error Message"] else: print( 'Unable to determine how to handle error, please review and press enter to continue...' ) input() return abstract.county.messages["Error Message"] elif alt == 'search': return False else: print( 'No error appears to have occurred, please review and press enter to continue...' ) input() return abstract.county.messages["Error Message"]
def update_download(browser, abstract, document): set_download_path_and_name_values(browser, abstract, document) wait_for_download(browser, abstract, document) naptime() rename_download(abstract, document) check_for_rename(abstract, document) abstract.report_document_download(document)
def access_pdf_viewer(browser, abstract, document): while not switch_into_frame(browser, abstract, document): print( 'Browser failed to access PDF viewer, refreshing and trying again...' ) browser.refresh() naptime()
def search(browser, abstract, document): open_url(browser, abstract.county.urls["Search Page"], abstract.county.titles["Search Page"], "document search page") check_login_status(browser, abstract) if not check_for_error(browser, abstract, document, 'search'): clear_search(browser, abstract, document) naptime() # Consider testing without this nap to see if necessary execute_search(browser, abstract, document)
def retry_execute_search(browser, abstract, document, search_status): while search_status == abstract.county.messages["Failed Search"]: print(f'Search failed for {document.extrapolate_value()},' f' executing search again.') execute_search(browser, abstract, document) naptime() search_status = wait_for_results(browser, abstract) return search_status
def open_search(browser, abstract, document): javascript_script_execution(browser, abstract.county.scripts["Search"]) navigation_tab = access_search_navigation_tab(browser, abstract, document) while not is_active_class(navigation_tab): print("Navigation tab not active, attempting to connect again.") naptime() # Allows time for navigation to load navigation_tab = access_search_navigation_tab(browser, abstract, document) assert abstract.county.titles["Search"]
def download_page(browser, abstract, document, count): prepare_for_download(abstract, document) open_download_page(browser, document) browser.execute_script('window.print();') naptime() update_download(browser, abstract, document) print( f'Successfully downloaded page {count + 1} for {document.extrapolate_value()}.' ) browser.back()
def get_related_documents_table_rows(browser, abstract, document_table, document): center_element(browser, document_table) related_documents_table_rows = locate_related_documents_table_rows( abstract, document, document_table) while related_documents_table_rows is False: print(f'Unable to locate the "Related Documents Table" rows for ' f'{document.extrapolate_value()}, trying again...') naptime() related_documents_table_rows = locate_related_documents_table_rows( abstract, document, document_table) return related_documents_table_rows
def build_document_download_information(browser, abstract, document): access_download_information(browser, abstract, document) while document.reception_number.strip() == '': print('Browser did not correctly access reception number for ' f'{document.extrapolate_value()}, trying again...') naptime() access_download_information(browser, abstract, document) record_value(abstract, 'reception number', document.reception_number) # Below is necessary until better logic order is figured out for 'handle_document_image_status' if len(abstract.dataframe['Reception Number']) != len( abstract.dataframe['Comments']): record_value(abstract, 'comments', '')
def open_search(browser, abstract): # Messy => figure out a better way to do this javascript_script_execution(browser, abstract.county.scripts["Search"]) naptime() # This will probably not work great when called during the 'login' process ###### search_navigation = locate_element_by_id( browser, abstract.county.ids["Search Navigation"], "search navigation", True) if is_active_class(search_navigation): return else: browser.execute_script(abstract.county.scripts["Search"]) assert abstract.county.titles["Search"]
def count_results(browser, abstract, document): click_button(browser, locate_element_by_id, abstract.county.buttons["Result Count"], "result count button", document) # Open Result Count naptime() naptime() result_count = locate_element_by_id(browser, abstract.county.ids["Result Count"], "result count", document=document) # Get Result Count # This doesn't work the way it's supposed to # Need to perform a match against the document number in order to find the correct count # Check leopard for options if int(result_count.text.split(' ')[-1]) > 1: document.number_results = 1
def handle_disclaimer(browser, abstract): javascript_script_execution( browser, abstract.county.scripts["Open Search"] ) disclaimer = locate_element_by_id(browser, abstract.county.ids["Disclaimer"], "disclaimer" ) if disclaimer.get_attribute('class') == abstract.county.classes["Disclaimer Active"]: click_button( browser, locate_element_by_id, abstract.county.buttons["Disclaimer"], "disclaimer button" ) naptime()
def get_search_status(browser, abstract): try: search_status_present = EC.presence_of_element_located( (By.TAG_NAME, abstract.county.tags["Search Status"])) WebDriverWait(browser, timeout).until(search_status_present) search_status = browser.find_element_by_tag_name( abstract.county.tags["Search Status"]).text return search_status except TimeoutException: print("Browser timed out trying to get current results.") except StaleElementReferenceException: print( 'Encountered a stale element reference exception trying to determine search status, ' 'refreshing & trying again.') browser.refresh() naptime() return None
def count_results(browser, abstract, document): # Wait for results table to load before getting count locate_element_by_id(browser, abstract.county.ids["Results Table"], "results table", False, document) # I don't think the above is doing anything useful naptime() # Need to find a better trigger to wait on result_count = locate_element_by_id(browser, abstract.county.ids["Result Count"], "result count", False, document) # This doesn't work the way it's supposed to # Need to perform a match against the document number in order to find the correct count # Check leopard for options if int(result_count.text.split(' ')[-1]) > 1: if document.type == "document_search": document.number_results = 1 elif document.type == "name": document.number_results = int(result_count.text.split(' ')[-1])
def handle_click_next_result_button(browser, abstract, document, button): while not click_result_button(browser, button): naptime() button = get_next_result_button(browser, abstract, document)
def previous_result(browser, abstract, document): previous_result_button = get_previous_result_button( browser, abstract, document) scroll_to_top(browser) previous_result_button.click() naptime()
def search(browser, abstract, document): open_url(browser, abstract.county.urls["Search Page"], abstract.county.titles["Search Page"], "document search page") clear_search(browser, abstract, document) naptime() # Consider testing without this nap to see if necessary execute_search(browser, abstract, document)
def validate_login(browser, login): if check_for_bad_server_response(browser): return_home(browser) naptime() login(browser) return True
def retry_search(browser, abstract, document): browser.refresh() naptime() search(browser, abstract, document)