CasperJS doesn't support Chinese language well.

50 views
Skip to first unread message

runc...@163.com

unread,
Nov 1, 2015, 9:35:51 PM11/1/15
to CasperJS
Now let's navigate to the website with the URL of http://www.cnblogs.com, and click the button with the name of "登录". 


Above is the procedure that I want to implement using CasperJS or PhantomJS, but I met a problem that it seems the CasperJS and PhantomJS doesn't support Chinese language well:

Below is my code:
// JavaScript source code
var address = 'http://www.cnblogs.com/';
var output1 = 'D:\capture1.png';
var casper = require('casper').create();
casper
.start(address).then(function () {
   
this.wait(10000).then(function () {
       
this.clickLabel('登录', 'a');
   
});
   
this.wait(10000).then(function () {
       
this.capture(output2);
   
});
});
casper
.run();

Is there anybody can deal with this problem? Thank you very much.
This is my e-mail: runc...@163.com
Hope to get your help soon.

apeg...@gmail.com

unread,
Nov 2, 2015, 2:05:27 AM11/2/15
to casp...@googlegroups.com
use Xpath

example 

var casper = require(‘casper’).create();

var x = require(‘casper’).selectXPath;

right click on an element and copy xpath 


<button type=‘button’ id=“button”>Clic</button>

var element = this.getElementInfo(x(‘button[id=“button"]'));


--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
 
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
---
You received this message because you are subscribed to the Google Groups "CasperJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casperjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

apeg...@gmail.com

unread,
Nov 2, 2015, 2:07:28 AM11/2/15
to casp...@googlegroups.com
var button = ‘’//*[@id="span_userinfo"]/a[1]';



On Nov 1, 2015, at 7:35 PM, runc...@163.com wrote:

runc...@163.com

unread,
Nov 2, 2015, 2:14:00 AM11/2/15
to CasperJS
Thank you Alex very much! And there is still a limit that I can only use the IE explorer in my company, and there is no plug-in available to get the element's xpath on page for IE explorer. What should I do? May I use part of the xpath to locate the element on page?

apeg...@gmail.com

unread,
Nov 2, 2015, 2:26:04 AM11/2/15
to casp...@googlegroups.com
use google chrome. Then install resurrectio from Google. You can find it on Chrome’s “Web Store”.  This will make life easier. Just follow the instructions on how to use it. I can help for debugging. If you can’t do that then do the following. 


casper.start(url, function() {
var html = this.getHTML():
utils.dump(html);
});

This will dump everything  into your terminal. Select the element from there (use CSS selector). You should look online for css selectors (W3C).

Cheers,

Alex 


runc...@163.com

unread,
Nov 2, 2015, 2:31:43 AM11/2/15
to CasperJS
So glad to get your help, thank you very much, Alex. I need to get the permission before download and it is complex, so maybe there is no better way to solve . Thank you Alex! I will try what you suggests me when I get home. Thanks you! Best regards.

apeg...@gmail.com

unread,
Nov 2, 2015, 2:33:39 AM11/2/15
to casp...@googlegroups.com
Glade I could help. Best of luck.

Cheers,

Alex 

Darren Cook

unread,
Nov 2, 2015, 3:40:59 AM11/2/15
to casp...@googlegroups.com
> Now let's navigate to the website with the URL of http://www.cnblogs.com,
> and click the button with the name of "登录".

There is no 登录 button (*).

That page is in UTF-8, so as long as your casper script is also in
UTF-8, I believe it should work - there should be nothing ascii or
English-specific in CasperJS.

However, as the other replies are hinting, it is more reliable to use
class names and ids, as sites might tweak their text copy, but they will
change their html structure less often.

Darren


*: I notice other's are saying to click #span_userinfo.
Here is what I see at that point:

<div id="cnts">
<div id="site_nav_top">代码改变世界</div>
<div id="login_area"><span id="span_userinfo"></span></div>
<div class="clear"></div>
</div>

Perhaps it uses the IP address to decide what buttons to show? So people
inside China see a sign-up button, while those of us outside are not
offered the chance?

apeg...@gmail.com

unread,
Nov 2, 2015, 3:43:20 AM11/2/15
to casp...@googlegroups.com
Just use the mouse event to click on it. If you translate the page its say’s “login”.

use xpath and perform mouse event.

runc...@163.com

unread,
Nov 2, 2015, 3:52:21 AM11/2/15
to CasperJS
I think so, maybe people from different places will see a different structure. Thank you :)

在 2015年11月2日星期一 UTC+8下午4:40:59,Darren Cook写道:

runc...@163.com

unread,
Nov 2, 2015, 3:53:01 AM11/2/15
to CasperJS
OK, let me have a try. Thank you very much~!

在 2015年11月2日星期一 UTC+8下午4:43:20,Alex peguero-cruz写道:

Ken

unread,
May 28, 2017, 10:54:46 PM5/28/17
to CasperJS
This is interesting scenario, not sure if it's working now for you?
Reply all
Reply to author
Forward
0 new messages