def export_the_table_as_a_pdf(): sales_results_html = browser.get_property(selector="css=#sales-results", property="outerHTML") pdf = PDF() pdf.html_to_pdf(sales_results_html, "output/sales_results.pdf")
def open_and_complete_form(url: str, constitutional_response: str, csv_filename: str): try: browser = Browser.Browser() browser.new_browser(headless=False) browser.new_page(url) button_response = "text=" + constitutional_response browser.click(selector=button_response) pdf = PDF() fileSystem = FileSystem() print(csv_filename) with open(csv_filename) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') line_count = 0 if not os.path.exists(run_archive_filepath): os.makedirs(run_archive_filepath) else: fileSystem.empty_directory(run_archive_filepath) for row in csv_reader: if line_count == 0: line_count += 1 else: try: print("Completing order " + row[0]) #browser.click(selector="id=head") #time.sleep(2) #browser.keyboard_key(action="press", key="ArrowDown") #browser.keyboard_key(action="press", key="Enter") #browser.press_keys('id=head', "Arrowdown 2", "Enter") #browser.click(selector='xpath=//select/option[@value="'+row[1]+'"]') browser.click( selector= 'xpath=//form/div/div/div/label[@for="id-body-' + row[2] + '"]') browser.fill_text( selector= 'xpath=//div/input[@placeholder="Enter the part number for the legs"]', txt=row[3]) browser.fill_text(selector="id=address", txt=row[4]) browser.select_options_by("id=head", SelectAttribute["value"], str(row[1])) browser.click(selector="id=preview") browser.click(selector="id=order") receipt_html_text = browser.get_text( selector="id=receipt") robot_previous_filepath = run_archive_filepath + "\\robot_preview_image_" + str( row[0]) + ".png" browser.wait_for_elements_state( selector="id=robot-preview-image") browser.take_screenshot( selector="id=robot-preview-image", filename=robot_previous_filepath, fullPage=True) receipt_file_path = run_archive_filepath + "\\receipt_file_" + str( row[0]) pdf.html_to_pdf(receipt_html_text, receipt_file_path + ".pdf") browser.click(selector="id=order-another") fileSystem.wait_until_created(robot_previous_filepath) browser.click(selector=button_response) pdf.add_watermark_image_to_pdf( image_path=robot_previous_filepath, output_path=receipt_file_path + "_robot_image.pdf", source_path=receipt_file_path + ".pdf") fileSystem.wait_until_created(path=receipt_file_path + "_robot_image.pdf") print("Order complete") except Exception as errorMessage: try: error_message = browser.get_text( selector= 'xpath=//div[@class="alert alert-danger"]') except: error_message = errorMessage finally: print("Failed to process order: " + str(error_message)) browser.playwright.close() browser.new_browser(headless=False) browser.new_page(url) button_response = "text=" + constitutional_response browser.click(selector=button_response) finally: print("Getting next order...") finally: try: browser.playwright.close() finally: print("all orders complete")