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
版权声明:本文标题:Unable to download file from SharePoint using Playwright - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742307329a2450179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论