[Python] Selenium WebDriver script for exporting data from Power BI dashboard encountering...

Discussão em 'Python' iniciado por Stack, Agosto 31, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to automate the process of exporting data from a table in a Power BI dashboard using Selenium WebDriver and encountering some issues. Here's a summary of what I'm trying to achieve and the problems I'm facing: [​IMG] [​IMG]

    Objective:

    • Navigate to a specific Power BI dashboard URL.
    • Locate a table within the dashboard.
    • Click on the "more options" button (represented by a "...") next to the table.
    • Click on the "Export data" option that appears.
    • Handle any dialog or modal that appears after clicking "Export data".
    • Click the final "Export" button to initiate the download.
    • Verify if the exported file (exported_data.csv) exists in the Downloads folder.

    Current Issues: I've implemented the script using Python and Selenium WebDriver for Microsoft Edge. The script fails consistently with an error message that doesn't provide clear guidance on what's wrong. ERROR:__main__:Error occurred: Message: Stacktrace: GetHandleVerifier [0x00007FF776C08132+13538] Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF776B91DE9+595465] (No symbol) [0x00007FF7769AE6CF] (No symbol) [0x00007FF7769F2960] (No symbol) [0x00007FF7769F2A1F] (No symbol) [0x00007FF776A2D627] (No symbol) [0x00007FF776A1203F] (No symbol) [0x00007FF7769E8147] (No symbol) [0x00007FF776A2B1EE] (No symbol) [0x00007FF776A11C63] (No symbol) [0x00007FF7769E766E] (No symbol) [0x00007FF7769E683C] (No symbol) [0x00007FF7769E7221] Microsoft::Applications::Events::EventProperty::to_string [0x00007FF776DC96D4+1099860] Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF776B0D8FC+53532] Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF776B00E25+1605] Microsoft::Applications::Events::EventProperty::to_string [0x00007FF776DC8665+1095653] Microsoft::Applications::Events::ILogConfiguration::eek:perator* [0x00007FF776B9C961+27777] Microsoft::Applications::Events::ILogConfiguration::eek:perator* [0x00007FF776B96CE4+4100] Microsoft::Applications::Events::ILogConfiguration::eek:perator* [0x00007FF776B96E1B+4411] Microsoft::Applications::Events::EventProperty::~EventProperty [0x00007FF776B8CFA0+575424] BaseThreadInitThunk [0x00007FF82639257D+29] RtlUserThreadStart [0x00007FF82660AF28+40]

    My code:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import os
    import time
    import logging

    # Setup logging
    logging.basicConfig(level=logging.INFO) # Set logging level to INFO
    logger = logging.getLogger(__name__)

    # Initialize the WebDriver (using Microsoft Edge in this example)
    driver = webdriver.Edge()

    try:
    # Open the Power BI dashboard
    driver.get("https://app.powerbi.com/groups/me/apps/abcdwd-dddddd2-4dc0-9a2e-e3a701c76f0b/reports/.......")

    # Wait for the dashboard to load
    WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, "reportContainer")))

    # Locate the table within the dashboard using the provided class
    table_locator = (By.CSS_SELECTOR, 'div.visualWrapper.report')
    table_element = WebDriverWait(driver, 30).until(EC.presence_of_element_located(table_locator))

    # Find the "more options" button next to the table and click it
    more_options_button_locator = (By.CSS_SELECTOR, 'button[data-testid="visual-more-options-btn"]')
    more_options_button = table_element.find_element(*more_options_button_locator)
    more_options_button.click()

    # Wait for the "Export data" option to appear and click it
    export_data_locator = (By.CSS_SELECTOR, 'button[data-testid="pbimenu-item.Export data"]')
    export_data_button = WebDriverWait(driver, 30).until(EC.element_to_be_clickable(export_data_locator))
    export_data_button.click()

    # Now handle the dialog/modal that appears after clicking "Export data"
    # Assuming there's no iframe switch needed, adjust if necessary

    # Wait for the final "Export" button and click it
    final_export_locator = (By.CSS_SELECTOR, 'button[data-testid="export-btn"]')
    final_export_button = WebDriverWait(driver, 30).until(EC.element_to_be_clickable(final_export_locator))
    final_export_button.click()

    # Wait for some time to allow the export process to complete (adjust as needed)
    time.sleep(10)

    # Example: Check if the exported file exists in the downloads folder
    download_path = os.path.expanduser('~\\Downloads') # Adjust for different OS if necessary
    exported_file = os.path.join(download_path, 'exported_data.csv')

    if os.path.exists(exported_file):
    logger.info("Exported file found at: %s", exported_file)
    else:
    logger.error("Exported file not found. Check export process or download manually.")

    except Exception as e:
    logger.error(f"Error occurred: {str(e)}")

    finally:
    # Close the WebDriver
    driver.quit()

    Continue reading...

Compartilhe esta Página