簡體   English   中英

CasperjJs找不到變量:獲取

[英]CasperjJs Can't find variable: fetch

我正在編寫一個簡單的腳本,登錄網站,然后 go 到另一個頁面並單擊按鈕。 好像可以找到按鈕,但是點擊后出現錯誤:

頁面錯誤:ReferenceError:找不到變量:獲取

我該如何解決這個問題?

  var casper = require('casper').create({   
        verbose: true, 
        logLevel: 'debug',
        pageSettings: {
             loadImages:  false,         // The WebPage instance used by Casper will
             loadPlugins: false,         // use these settings
             userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
        }
    });


    //print out all the messages in the headless browser context
    casper.on('remote.message', function(msg) {
        this.echo('remote message caught: ' + msg);
    });

    // print out all the messages in the headless browser context
    casper.on("page.error", function(msg, trace) {
        this.echo("Page Error: " + msg, "ERROR");
    });

    casper.on('resource.error', function(msg) {
        this.echo('resource.error caught: ' + msg);
    });



    var url = 'https://firstPage.com';

    casper.start(url, function() {

         this.evaluate(function() {
                document.getElementById("login").value = "name@email.com";
                document.getElementById("password").value = "pass";
                document.querySelector("loginButton").click();
            });

    });


    casper.thenOpen('https://secondPage.com', function() { 
         console.log("Page Title " + document.title);
      });
    casper.waitForSelector('[data-content~="OK"]', function() {
      this.click('[data-content~="OK"]');
    })

fetch不會顯示為您在腳本上調用的變量或 DOM 元素,這很奇怪,但在這一行中,我假設您正在調用class loginButton

document.querySelector("loginButton").click();

如果它是 class 你應該把. (或#如果它是一個 ID),否則它將尋找一個不存在的 loginButton 元素。 嘗試:

document.querySelector(".loginButton").click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM