Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

How does one clear a text input? Pressing backspace a lot feels dirty. #133

Closed
ozymandias547 opened this issue Aug 1, 2017 · 2 comments
Closed

Comments

@ozymandias547
Copy link

ozymandias547 commented Aug 1, 2017

How does one clear a text input? Pressing backspace a lot feels dirty.

On the flipside, injecting some javascript and clearing that way is causing some weird issues.

Could we have a setValue or clear API method for inputs?

@forclan
Copy link

forclan commented Aug 2, 2017

You can run you own code in evaluate function like this:

const {Chromeless} = require('chromeless');

async function run() {
    // use local chrome
    const chromeless = new Chromeless({remote: false});

    const links = await chromeless
        .goto('https://www.google.com')
        .type('chromeless', 'input[name="q"]')
        .press(13)
        .wait('#resultStats')
        .evaluate(() => {
            function clearInputDomValue(queryStr) {
                const dom = document.querySelector(queryStr);
                if (dom) {
                    dom.value = '';
                    return 'success';
                } else {
                    console.error('failed, query is', queryStr);
                    return 'failure';
                }
            }
            clearResult('#sbhost');
        })
        .scrollTo(0, 1000);

    // do not close chrome after execution, so that if you do not start
    // chrome in 'headless' mode, you can see the result in chrome
    // await chromeless.end();
}

run().catch(console.error.bind(console));

@adieuadieu
Copy link
Collaborator

Closing as #151 was merged. Will be released in v1.2.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants