question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Add 'clear' option to the .type() function

See original GitHub issue

Function concerned : .type - api here

Basically, add a boolean clear into the options so we specify if we want to clear the field before typing.

page.type('#myinput', 'toto', {clear: true})

This would clear any existing input into #myinput then it would type toto.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:43
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
samfultonjrcommented, Jul 17, 2019

Made my own little function, pretty easy to use for those who are seeking this feature.

async function clear(page, selector) {
  await page.evaluate(selector => {
    document.querySelector(selector).value = "";
  }, selector);
}

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.type("input.search","hello");
  await clear(page,"input.search");

  await browser.close();
})();

OR you can add it to the page class to use page.clear(selector); like this,

clear = async function ( selector) {
  await this.evaluate(selector => {
    document.querySelector(selector).value = "";
  }, selector);
};


(async () => {
  const browser = await puppeteer.launch({headless:false});
  const page = await browser.newPage();
  page.clear = clear;
  await page.goto('https://www.w3schools.com/html/html_forms.asp');
  await page.type("input[value]","hello");
  await page.clear("input[value]");

  await browser.close();
})();
12reactions
hmmhmmhmcommented, May 31, 2019

@samfultonschool thanks! it’s very useful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delete Features—ArcGIS REST APIs
This option was added at 10.5 and works with ArcGIS Server services only. Specifies whether the response will report the time that features...
Read more >
Clear or remove a filter - Microsoft Support
If you want to completely remove filters, go to the Data tab and click the Filter button, or use the keyboard shortcut Alt+D+F+F....
Read more >
Clear memory - Stata
You can clear the entire dataset without affecting macros and programs by typing clear. You can also type clear all. This command has...
Read more >
HTTP request methods - MDN Web Docs
Chrome Edge CONNECT Full support. ChromeYes. Toggle history Full support. Edge12. Toggle history DELETE Full support. ChromeYes. Toggle history Full support. Edge12. Toggle history GET Full...
Read more >
Network features reference - Chrome Developers
on the Network panel to clear all requests from the Requests table. The Clear button. ... Open the Throttling menu and select Custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found