簡體   English   中英

無頭模式劇作家沒有按預期工作

[英]headless mode playwright not working as inteded

嗨,我的代碼有問題,當我在無頭模式下使用劇作家開始抓取代碼時:當我到達等待導航以登錄程序停止工作時為真,當我以無頭模式啟動它時,我不知道為什么會導致: 錯誤的; 我沒有錯誤地到達我的最終目的地。 這是我的代碼:

function ashScraping() {
  (async () => {
    const browser = await chromium.launch({
      headless: false,
      slowmo: 300,
      timeout: 70000,
      acceptDownloads: true,
    });
    const context = await browser.newContext();
    const page = await context.newPage();
    await page.goto('https://www.thePageImUsing.com/login');
    await page.locator('input[name="txtUserID"]').click();
    await page.locator('input[name="txtUserID"]').fill(`${user}`);
    await page.locator('input[name="txtPassword"]').click();
    await page.locator('input[name="txtPassword"]').fill(`${cont}`);
    await Promise.all([
      page.waitForNavigation(/*{ url: 'https://home.thePageImUsing.com' }*/),
      page.locator('text=login').click()
    ]);
    const [page1] = await Promise.all([
      page.waitForEvent('popup'),
      page.locator('something..something').click()
    ]);
    await page1.locator('input[name="txtShpno"]').click();
    await page1.locator('input[name="txtShpno"]').fill(`${bodega}`);
    await page1.locator('input:has-text("Buscar")').click();
    await Promise.all([
      page.waitForNavigation(/*{ url: 'home.thePageImUsing.com' }*/),
    ]);
    await page.locator('text=Artículos').click();
    await page.locator('text=Artículos').click();
    await page.locator('text=Artículos').click();
    await page.locator('text=Programa de clientes').click();
    await page.locator('#rdoWarehouse_0').check();
    await page.locator('#rdoAvailability_2').check();
    const [download] = await Promise.all([
      page.waitForEvent('download'),
      page.on('dialog', dialog => dialog.accept()),
      await page.locator('#cmdExport').click(),
    ]);
    const path = download.suggestedFilename();
    await download.saveAs(path);
    await context.close();
    await browser.close();
  })();
};

ashScraping();

所以出於隱私原因我修改了代碼的某些部分,但上下文是相同的。 我歡迎任何可以指出我錯誤的答案。

現在,當我以無頭模式啟動軟件時:是的,這是錯誤:

line 23: waitfornavigation: timeout.

您可以檢查而不是等待導航嗎: S1:單擊 url S2:然后在下一頁中使用等待選擇器檢查任何元素...。

await Promise.all([
    page.click('.ffwHVz'),
    page.waitForSelector('.icon-User-Filled'),
  ]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM