I have developed a code via Robocorp and I have a problem. The mission is to upload a csv file to a financer's platform to be able to track paid and unpaid invoices. At one point in the code, I asked the bot to click on an icon and wait for another “download” icon to appear, but it had trouble catching that icon. I gave it several selectors but nothing helped. here's the code:
# Click on the "Export" button
browser_lib.click_element("xpath://button[contains(., 'Export')]")
logger.info("Button 'Export' clicked")
# Click on download icon
browser_lib.wait_until_element_is_visible(
"xpath://a-action-icon[@icon='insert_drive_file']", timeout=30
)
browser_lib.click_element(
"xpath://a-action-icon[@icon='insert_drive_file']"
)
logger.info("Download button (insert_drive_file) clicked.")
# Wait for file to download (max. 40 seconds)
downloads_folder = os.path.join(os.path.expanduser("~"), 'Downloads')
downloaded_file = None
start_time = time.time()
while time.time() - start_time < 40:
list_of_files = glob. glob(os.path.join(downloads_folder, '*.xls*'))
if not list_of_files:
list_of_files = glob.glob(os.path.join(downloads_folder, '*.xlsx'))
if list_of_files:
downloaded_file = max(list_of_files, key=os.path.getctime)
break
time.sleep(1)
if downloaded_file:
logger.info(f "Downloaded file found: {downloaded_file}")
else:
logger.error("No exported file found after 40 seconds")
logger.info("Task completed successfully")
except Exception as e:
logger.error(f "Erreur rencontrée : {e}")
logger.error(traceback.format_exc())
try:
if browser_lib.get_browser_aliases():
screenshot_path = os.path.join(os.getcwd(), "erreur_connexion. png")
browser_lib.capture_page_screenshot(screenshot_path)
logger.info(f "Capture d'écran enregistrée : {screenshot_path}")
except Exception:
pass
finally:
browser_lib.close_browser()
here are the elements I have: arrow_downward
Rel cssselector : body > div:nth-child(5) > div:nth-child(1) > div:nth-child(2) > o-export-management-popup:nth-child(1) > div:nth-child(1) > div:nth-child(4) > p-table:nth-child(1) > div:nth-child(1) > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(7) > m-export-management-status:nth-child(1) > div:nth-child(1) > button:nth-child(2) > mat-icon:nth-child(1)
Rel Xpath : //tbody/tr1/td[7]/m-export-management-status1/div1/button1/mat-icon[1]enter image description here