在输入类型搜索中按up

时间:2019-10-31 09:47:47

标签: keyboard puppeteer enter

我想按回车键,在输入完之后,什么都没有发生,这不是单击链接或按钮

<div class="search-input">
    <a class="search machin" style="display:none;z-index: 0;position: absolute;"></a>
    <input type="search" id="global-search"> //events jquery keypress and keyup
    <a class="close-search" style="z-index: 0;">
       <i class="m times"></i>
    </a>
</div>
jquery : function(t) {
  return "undefined" != typeof w && w.event.triggered !== t.type ? w.event.dispatch.apply(e, 
arguments) : void 0
}

我用屏幕截图验证了输入类型=“ search”的填充是否正确,并且是。

await page.focus('#global-search');
await page.type('#global-search',"string to find"); //it works

await page.$eval('#global-search', (el, value) => el.value = value, myLocalValue);//it works

我试试这个:     await page.keyboard.press("Enter"); 要么     await page.keyboard.down('Enter');     await page.keyboard.up('Enter');

按下Enter键必须完成url https://lesite.fr/recherche?q=string_to_find,但情况并非如此{@ 3}}

我必须在其中找到搜索结果

<div class="h-container">
    <div class="h">
        <div class="h-image SearchBanner">
            <img src="/-/media/_banner.jpg">
            <div class="rot-block"></div>
        </div>
        <div class="h-details">
            <h1>16 RÉSULTATS</h1>
            <div class="search-result">HERE THE RESULT<span class="secondary-title">string to find</span></div>
        </div>
    </div>
</div>

问题在于网址未完成

我读了很多Google搜索(https://lesite.fr/。)

帮助

2 个答案:

答案 0 :(得分:0)

在此工作示例中,它将从HTML输入的搜索标记中搜索Google。

请尝试此变通办法,并告诉我是否可以解决您的问题。 还要尝试在其上方的每行4条注释。

const puppeteer = require ('puppeteer')

;(async () => {

    const browser = await puppeteer.launch ({
        headless: false,
        devtools: true,
        slowMo: 50 // delete this if you like
    })
    const contentHTML = '<form name="search" method="get" action="https://www.google.com/search?"><div class="search-input"><a class="search machin" style="display:none;z-index: 0;position: absolute;"></a><input type="search" id="global-search" name="q"><a class="close-search" style="z-index: 0;"><i class="m times"></i></a></div></form>'
    const page = (await browser.pages())[0]
    // const google = await page.goto('https://www.google.com', {waitUntil: 'networkidle2'})
    const setContent = await page.setContent(contentHTML, {waitUntil: 'domcontentloaded'})

    const focusSearch = await page.focus('#global-search')
    const typeSearch = await page.type('#global-search',"string_to_find") //it works

    const searchSubmitted = await Promise.all([
        page.waitForNavigation({waitUntil: 'domcontentloaded'}),

        // const pressReturn = page.type('#global-search', '\r'),
        // const pressReturn = page.type('#global-search', String.fromCharCode(13)),
        // const pressReturn = page.keyboard.type('\n'),
        // const pressReturn = page.keyboard.down('NumpadEnter'),
        const pressReturn = page.keyboard.press('Enter') // 4 LINES ABOVE ALSO WORKS, TRY THEM ALL
    ])

    // 'Enter': {'keyCode': 13, 'code': 'Enter', 'key': 'Enter', 'text': '\r'}

    // <div class="search-result">HERE THE RESULT<span class="secondary-title">string to find</span></div>

    // const searchString = await page.$eval('span.secondary-title', el => el.innerText);


})()

答案 1 :(得分:0)

        await page.focus('#header > div.component.container.float-wrapper > div.search > div > div.search-input');
         await page.type('#header > div.component.container.float-wrapper > div.search > div > div.search-input',"PSG");
        await page.keyboard.press('ArrowRight');
        await page.focus('#header > div.component.container.float-wrapper > div.search > div > div.search-input');
        await page.keyboard.press('Enter'); // Enter Key
        await page.keyboard.press('NumpadEnter'); // Numeric Keypad Enter Key
        await page.keyboard.press('\n'); // Shortcut for Enter Key
        await page.keyboard.press('\r'); // Shortcut for Enter Key

搜索30小时后即可工作

非常感谢您的回答