seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5k stars 941 forks source link

Help with downlaoding a tableau dashboard using selenium base #2548

Closed Skeo220 closed 6 months ago

Skeo220 commented 6 months ago

Hello,

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)

I have tried many other things but nothing works. If anyone can help that would be amazing. Thanks

mdmintz commented 6 months ago

Hello, 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.

Skeo220 commented 6 months ago

It worked, thank you so much for your help!

On Thu, Feb 29, 2024 at 9:08 AM Michael Mintz @.***> wrote:

Hello, this downloads the PDF of the first chart displayed:

from seleniumbase import BaseCaseBaseCase.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.

— Reply to this email directly, view it on GitHub https://github.com/seleniumbase/SeleniumBase/issues/2548#issuecomment-1971465398, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3FLG5CA7YJIO4LEHS4JB7DYV5I6VAVCNFSM6AAAAABD7NJDL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZRGQ3DKMZZHA . You are receiving this because you authored the thread.Message ID: @.***>