我在将多行字符输入到所见即所得输入中时遇到一些问题。
我使用这个代码:
await page.goto('https://someurl.com', {waitUntil: 'networkidle0'});
//This button display a popup when a click is done
await page.waitForSelector('.sendBtn', {visible: true});
await page.click('.sendBtn');
//Wait for modal input field to appear
await page.waitForSelector('.modal.input', {visible: true});
const textInput = await page.$('.modal.input');
await textInput.click();
await textInput.focus();
await textInput.type('Hello,');
await textInput.press('Enter');
await textInput.press('Enter');
await textInput.type('Some text ');
await textInput.press('Enter');
await textInput.press('Enter');
await textInput.type('Some text again');
await textInput.press('Enter');
await textInput.press('Enter');
await textInput.press('Enter');
await textInput.type('Some text to the end');
它可以工作,但文本的第一个字符总是丢失,有时是一个,有时是 10 个字符......
真的很烦人。
我尝试添加 focus()、click()、networkidle0 等待,但没有任何效果。
看来这个问题是众所周知的,但我不明白为什么这样一个明显的老问题仍然相关,为什么它总是被关闭,为什么它总是在重新打开之前关闭,从 2017 年开始! :
https://github.com/puppeteer/puppeteer/issues/1648 https://github.com/puppeteer/puppeteer/issues/1648
或者可能是因为模态未完全加载?即使我等待模式中的输入字段可见?
我添加了一个:“等待 page.waitFor(500);”
它可以工作,但它很丑......
关于这个 bug 有一个开放的 github 问题:https://github.com/puppeteer/puppeteer/issues/1648 https://github.com/puppeteer/puppeteer/issues/1648
同时您可以执行以下解决方法:
await this.page.waitFor(1000);
await this.page.waitForSelector("your selector", {visible: true, timeout: 60000});
await this.page.focus("your selector");
await this.page.type("your selector", text, {delay: 100});
尽管我使用已弃用的函数:waitFor(1000),但这对我有用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)