Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filling in input values before button click #224

Open
halshing opened this issue Aug 27, 2018 · 0 comments
Open

Filling in input values before button click #224

halshing opened this issue Aug 27, 2018 · 0 comments

Comments

@halshing
Copy link

Hi there,

I'm trying to figure out how I can write text to an input field before I click a button on the page. The site is using Angular and the text I'm trying to scrape is actually inside a modal that appears once the button is clicked and grabs text from the input field. If there is nothing found in the input field when the button is clicked, the modal won't appear on the page, and I won't be able to scrape the contents of the modal.

Any thoughts on how to accomplish this?

Here's my code, but it throws the errors below:

let doWork = () => {
    return new Promise(resolve => {
        let results = [];
        osmosis
            .get(_url)
            .find('nav[role=navigation] .container')
            .then(function (ctx, data, next) {
                let field = ctx.querySelector('div:nth-of-type(2) > ul:nth-of-type(2) > li > div > input');
                field.value = '1';
                next(ctx, data);
            })
            .click('div:nth-of-type(2) > ul:nth-of-type(2) > li > div > button')
            .then(function (ctx) { // This doesn't get executed
                let modal = document.querySelector('.modal-content');
                console.log(modal.innerHTML);
            })
            .find('.modal-content')
            .set('content')
            .data(data => {
                results.push(data);
            })
            .done(() => {
                console.log(results);
                resolve();
            })
            .error(console.error)
    });
}

Errors:

[libxmljs-dom] Window.onerror:  https://www.somewebsite.com.<script>[1]:3
        "@context": "http://schema.org",
                  ^

SyntaxError: Unexpected token :
    at Object.createScript (vm.js:80:10)
    at Window.eval (D:\..\..\node_modules\libxmljs-dom\lib\Window.js:138:29)
    at Window.__evalScripts (D:\..\..\node_modules\libxmljs-dom\lib\Window.js:100:24)
    at Window.set document [as document] (D:\..\..\node_modules\libxmljs-dom\lib\Window.js:62:14)
    at new Window (D:\..\..\node_modules\libxmljs-dom\lib\Window.js:23:23)
    at Document.get defaultView [as defaultView] (D:\..\..\node_modules\libxmljs-dom\lib\Document.js:127:29)
    at Command.Click [as cb] (D:\..\..\node_modules\osmosis\lib\commands\click.js:36:27)
    at Command.start (D:\..\..\node_modules\osmosis\lib\Command.js:159:21)
    at D:\..\..\node_modules\osmosis\lib\Command.js:166:18
    at D:\..\..\node_modules\osmosis\lib\commands\then.js:68:17
ReferenceError: Node is not defined
    at /../../dist/bower_components/angular/angular.min.js?v=1.4.9:178:20
    at /../../dist/bower_components/angular/angular.min.js?v=1.4.9:299:487
    at ContextifyScript.Script.runInContext (vm.js:59:29)
    at Window.eval (D:\..\..\node_modules\libxmljs-dom\lib\Window.js:139:20)
    at D:\..\..\node_modules\libxmljs-dom\lib\Window.js:90:28
    at D:\..\..\node_modules\libxmljs-dom\lib\HttpRequest.js:43:9
    at done (D:\..\..\node_modules\needle\lib\needle.js:432:14)
    at PassThrough.<anonymous> (D:\..\..\node_modules\needle\lib\needle.js:671:11)
    at emitNone (events.js:111:20)
    at PassThrough.emit (events.js:208:7)
/../../dist/bower_components/angular/angular.min.js?v=1.4.9:178
ja.th=ja.td;var Rf=Node.prototype.contains||function(a){return!!(this.compareDocumentPosition(a)&16)},Qa=S.prototype={ready:function(a){function b(){d||(d=!0,a())}var d=!1;"complete"===U.readyState?setTimeout(b):(this.on("DOMContentLoaded",b),S(R).on("load",b))},toString:function(){var a=[];p(this,function(b){a.push(""+b)});return"["+a.join(", ")+"]"},eq:function(a){return 0<=a?D(this[a]):D(this[this.length+a])},length:0,push:wg,sort:[].sort,splice:[].splice},Bb={};p("multiple selected checked disabled readOnly required open".split(" "),
                   ^

Thanks!

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

No branches or pull requests

1 participant