segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.54k stars 1.08k forks source link

How I can get nightmare instance. #1602

Open ParseDark opened 4 years ago

ParseDark commented 4 years ago

I want to for-loop dom and hover every one. But I can't.

ParseDark commented 4 years ago

Why in action I can't get the instance????? So wire.

ParseDark commented 4 years ago

click should be accept a function. function return dom.

ParseDark commented 4 years ago
Nightmare.action('getTarget', {
      run(done) {
          debugger
          let s = ''
        this.realClick('a');
        this.evaluate_now(() => {
            const arr = Array.prototype.slice.call(document.querySelectorAll('h3'))
            const result = arr.find(i => i.innerHTML.includes('s'))
            console.log(result.length)

            if(result.classList) {
                const res = result.classList;
                const selector = Object.entries(res).map(([key, value]) => value).map(i => ('.' + i)).join('');
                s = selector
                return selector
            }

            return false
        }, done);
  },

if in a action can't call instance I will be haven't any values.