English 中文(简体)
生产者——日历
原标题:Puppeteer - Calendar Widget will not open
问题回答

如果您要操作document.querySelectorAll(#datePicker div[}=“input-atant-icon fa-calendar”),你会看到,有6项内容与你的遴选人相符。 然而,只有最后2条是可以理解的。

这里,新法典希望:

const puppeteer = require( puppeteer )
const fs = require( fs/promises )

async function start(){
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto("https://www.ihg.com/hotels/us/en/reservation", {waitUntil: "domcontentloaded"});

    // This is for check in
    await page.click( #datePicker > span > span > lib-datepicker-date-field:nth-child(2) > span > span > div );

    // run other stuff

    // Check out
    await page.click( #datePicker > span > span > lib-datepicker-date-field:nth-child(4) > span > span > div );

    // run other stuff

    // waitForSelector 
    await page.waitForSelector( span[class="datepicker-field"] span[class="input-and-icon brand-outline"] );

    await browser.close() 
}

start() 

序言:该网站是一个像安吉斯·尤里察这样的景象。 它重复了身份识别特征的内容,以及大量的同化行为和一般的杂乱,因此它赢得的机体很容易实现自动化。

这可能是一个xy problem,在网络拆解中经常出现:有一种趋势认为你需要像用户那样行事(“我需要打开日期选择”。 但是,在拟议解决方案Y中,考虑对真正的问题X(“我能利用网站接受的任何技术把日期投入集中起来吗?” )和使用<代码> 类型()和关键板,以便把投入箱装上,而不担心日期选择自动化。

考虑到最后一点似乎是对每个要素的正确投入,你可以选择这些要素,然后利用关键板在新内容中删除目前的日期和类型。 登机帮助确保启动适当的活动,使网站了解这一变化。 当现场验证和操纵日期时,有一线星像,因此,Im每天进入检查点,然后是目的地,然后检查。

const puppeteer = require("puppeteer"); // ^21.6.0

const url = "<Your URL>";

let browser;
(async () => {
  browser = await puppeteer.launch({headless: "new"});
  const [page] = await browser.pages();
  const ua =
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36";
  await page.setUserAgent(ua);
  await page.goto(url);

  const enterDate = async (el, date) => {
    const length = await el.evaluate(el => el.value.length);
    await el.focus();

    for (let i = 0; i < length; i++) {
      await page.keyboard.press("Backspace");
      await page.keyboard.press("Delete");
    }

    await el.type(date);
    await page.keyboard.press("Enter");
  };

  const getLastEl = sel => page.evaluateHandle(`
    [...document.querySelectorAll("${sel}")].pop()
  `);

  const destinationEl = await getLastEl("#dest-input");
  const checkInEl = await getLastEl("#checkInDate");
  const checkOutEl = await getLastEl("#checkOutDate");
  await enterDate(checkInEl, "05/21/2024");
  await destinationEl.type("miami");
  await enterDate(checkOutEl, "06/07/2024");
  await page.screenshot({path: "test.png"});
})()
  .catch(err => console.error(err))
  .finally(() => browser?.close());

采用多功能载荷一般是好的,但我注意到,有些情况下投入的准备程度相当高,因此,我回头再去装载,速度较慢。 也许可以确定一种假设,即你可以核查准备程度,这种准备程度比负荷更精确,让你回头上下载,但我建议首先注重正确性,然后加快(作为保持这一员额范围的一种做法)。

You may need to play with this a bit, but hopefully it communicates one possible general strategy. Proceed carefully.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签