fix(lucida): Use locators #9
This commit is contained in:
parent
48fe8886f7
commit
fe523c91fe
1 changed files with 11 additions and 6 deletions
|
@ -1,22 +1,27 @@
|
||||||
import {firefox, Page, BrowserContext, Download, Browser, Locator} from 'playwright';
|
import {BrowserContext, Download, Locator, Page} from 'playwright';
|
||||||
|
|
||||||
export async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise<boolean | string> {
|
export async function openAlbum(album: URL, context: BrowserContext): Promise<Page> {
|
||||||
const page: Page = await context.newPage();
|
const page: Page = await context.newPage();
|
||||||
|
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
|
||||||
// Fill in the album URL
|
// Fill in the album URL
|
||||||
await page.fill('input[id="download"]', album.href);
|
await page.locator('input[id="download"]').first().fill(album.href);
|
||||||
|
|
||||||
// Wait for the XHR request to complete
|
// Wait for the XHR request to complete
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
page.waitForResponse(res => res.url().includes('/api/load') && res.status() == 200),
|
page.waitForResponse(res => res.url().includes('/api/load') && res.status() == 200),
|
||||||
page.click('input[id="go"]'),
|
page.locator('input[id="go"]').first().click(),
|
||||||
page.waitForLoadState('domcontentloaded')
|
page.waitForLoadState('domcontentloaded')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise<boolean | string> {
|
||||||
|
const page: Page = await openAlbum(album, context);
|
||||||
|
|
||||||
// Check 'Hide my download from recently downloaded' checkbox
|
// Check 'Hide my download from recently downloaded' checkbox
|
||||||
await page.check('input[id="hide-from-ticker"]');
|
await page.locator('input[id="hide-from-recent"]').first().setChecked(true);
|
||||||
|
|
||||||
// Parse info
|
// Parse info
|
||||||
const albumName: string = (await page.locator('h1[class="svelte-6pt9ji"]').last().innerText()).trim();
|
const albumName: string = (await page.locator('h1[class="svelte-6pt9ji"]').last().innerText()).trim();
|
||||||
|
|
Reference in a new issue