Downloading a tableau dashboard using selenuimbase

27 Views Asked by At

I am trying to create a script that downloads my tableau public viz and sends it to me. It is for a project. I keep running into problems after I click on the download button

from seleniumbase import BaseCase
import pyautogui

class Test(BaseCase): def test_basic(self): # Open Tableau page self.open("https://public.tableau.com/app/discover/viz-of-the-day") self.maximize_window()

    # Wait for page to load
    self.wait_for_ready_state_complete()
    
    # Click on the first visualization
    self.click("ul._galleryList_1hb88_2 li:first-child a")
    
    # Wait for page to load
    self.wait_for_ready_state_complete()
    
    
    self.sleep(2)
    self.click("//*[@id='root']/div/div[4]/div[1]/div/div[2]/button[4]")
       
    self.sleep(5)
    pyautogui.press('enter')
    
    self.sleep(5)
BaseCase.main(name, file)

This works but it only allows me to download the dashboard as a png.

I tried using the code below to help going down to the pdf but it doesn't work.

from seleniumbase import BaseCase
import pyautogui

class Test(BaseCase): def test_basic(self): # Open Tableau page self.open("https://public.tableau.com/app/discover/viz-of-the-day") self.maximize_window()

    # Wait for page to load
    self.wait_for_ready_state_complete()
    
    # Click on the first visualization
    self.click("ul._galleryList_1hb88_2 li:first-child a")
    
    # Wait for page to load
    self.wait_for_ready_state_complete()
    
    
    self.sleep(2)
    self.click("//*[@id='root']/div/div[4]/div[1]/div/div[2]/button[4]")
       
    self.sleep(5)
    pyautogui.press('tab')
        self.sleep(5)
    pyautogui.press('tab')
        self.sleep(5)
    pyautogui.press('tab')
        self.sleep(5)
    pyautogui.press('enter')
    
    self.sleep(5)
BaseCase.main(name, file)
1

There are 1 best solutions below

0
Michael Mintz On

This downloads the PDF of the first chart displayed:

from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)

class TableauTest(BaseCase):
    def test_tableau_pdf_download(self):
        self.open("https://public.tableau.com/app/discover/viz-of-the-day")
        self.click('img[alt="Workbook thumbnail"]')
        self.sleep(4)
        self.click('button[data-tip="Download"]')
        self.sleep(1)
        self.switch_to_frame('iframe[title="Data Visualization"]')
        self.click('button[data-tb-test-id="DownloadPdf-Button"]')
        self.click('button[data-tb-test-id="export-pdf-export-Button"]')

        breakpoint()

There's a breakpoint() at the end to pause the script with the browser window still open. Type c and press Enter to continue from the breakpoint. Adjust timing as needed. This should be enough to get you started on the right path.