admin管理员组

文章数量:1336434

I am trying to download files from SharePoint using Playwright (Java) in persistent context mode on Edge browser. On clicking download on SharePoint site, it will download a file with a random name. It doesn't actually download the file. Even if I manually click download on the Playwright browser, it's the same. Does anyone know how to get around this please? Is this something to do with authentication? Since I'm using persistent mode with an user profile that has the access rights, I can navigate freely on the SharePoint but it cannot download files. I have to use Playwright for this.

I tried to copy and paste the session variables of SharePoint site by normally opening Edge and navigating to the site (not using Playwright) and paste them to the Playwright browser then refresh the page but doesn't seem to work.

Below is my code, I have simplified it by not providing some variable values:

Playwright playwright = Playwright.create();

BrowserType.LaunchPersistentContextOptions options = new BrowserType.LaunchPersistentContextOptions()
        .setHeadless(false)
        .setChannel("msedge")
        .setAcceptDownloads(true)
        .setDownloadsPath(Paths.get(downloadDir));

BrowserContext context = playwright.chromium().launchPersistentContext(Paths.get(userProfile), options);

Page page = context.newPage();
context.clearCookies();

// Navigating to SharePoint
page.navigate(sharePointUrl);
page.waitForLoadState();

// Download file by clicking download button
Download download = page.waitForDownload(() -> {
        page.locator(xPathDownloadButton).click();
        page.waitForLoadState();
        });

download.saveAs(Paths.get(downloadDir + download.suggestedFilename()));

context.close();
playwright.close();

I would appreciate your help.

Many thanks.

本文标签: Unable to download file from SharePoint using PlaywrightStack Overflow