Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:46:08+00:00 2026-06-16T13:46:08+00:00

I am using casperjs and following is the code var casper = require(‘casper’).create(); var

  • 0

I am using casperjs and following is the code

var casper = require('casper').create();
var x = require('casper').selectXPath;

casper.start('http://google.co.in/', function() {
    // search for 'casperjs' from google form
    this.test.assertExists(x('//*[@type="text"]'), 'the element exists');

});
casper.run(function() {
    // echo results in some pretty fashion
    this.echo('').exit();
});

it wasn’t able to find any element with attribute type as text though there are plenty.

This is the output I get

FAIL the element exists
#    type: assertExists
#    subject: false
#    selector: {"type":"xpath","path":"//*[@type=\"text\"]"}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:46:09+00:00Added an answer on June 16, 2026 at 1:46 pm

    Google has been known to not be bot-friendly. In order for this to work, you must set the UserAgent.

    This was tested under CasperJS-1.0.0 and PhantomJS-1.8.0

    var casper = require('casper').create({
      pageSettings: {
        userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/25.0.1349.2 Safari/537.21'
      }
    });
    var x = require('casper').selectXPath;
    
    casper.start('http://google.co.in/', function() {
      // search for 'casperjs' from google form
      this.test.assertExists(x('//*[@type="text"]'), 'the element exists');
      this.test.assertExists({
        type: 'xpath',
        path: '//*[@type="text"]'
      }, 'the element exists');
    });
    
    casper.run(function() {
      // echo results in some pretty fashion
      this.echo('').exit();
    });
    

    You can visit http://whatsmyuseragent.com/ to see what your current UserAgent is.

    Update: Removed CasperJS-1.0.0 code in favor of backwards-compatible code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code using casper.js doesn't output This is thenEvaluate string because Twitter.com disabled
I built a simpel indexer using CasperJS. I would like Google Analytics to ignore
Using this code, the following execution yields strange results: C 100 R W The
Using the DateTime class, if I try to run the following code: $mydate =
Using this is very helpful when trying to generate html code in c#. var
Using MongoDB C# Driver (official form 10gen), I'm doing the following code: using (database.RequestStart())
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using the following as an example (with $db being a previously created database connection
Using the following database table structure: Order Table: OrderId OrderName OrderItem Table: OrderId ItemId
I'm trying to test a page using CasperJS, in particular I want to poke

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.