I'm trying to get the list of links on the menu on the left on this page: http://www.hpenterprisesecurity.com/vulncat
the first thing I'm trying to do is click the "Expand All" link (on the top left corner) so the list gets expanded.
I have tried multiple ways to use the Xpath in different ways with no success on this page, this was my last try:
casper.start('http://www.hpenterprisesecurity.com/vulncat', function() {
casper.wait(5000);
this.echo("---------- TITLE: ");
this.echo(this.getTitle());
});
casper.thenClick(x('//*[#id="theContentCenter"]/div/p/a[1]/strong[contains(text(),"Expand")]'),function(){
casper.wait(5000,function(){
casper.capture("expanded.png");
});
});
Maybe since the page lacks Ids and Tags for most elements my approach won't work?
Thanks
the set-up:
casper = require('casper').create({
verbose:true,
logLevel:"debug"
});
casper.userAgent('Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405');
casper.viewport = {width: 1280, height: 720};
var x = require('casper').selectXPath;
phantomjs: 1.9.8
casperjs: 1.1.0-beta3
RESOURCE ERROR:
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: http://www.hpenterprisesecurity.com/vulncat, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html"
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/header.html, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/all.html, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/intro.html, type=Other, willNavigate=true, isMainFrame=false
ResourceError: {
"errorCode": 203,
"errorString": "Error downloading http://www.hpenterprisesecurity.com/vulncat/en/vulncat/css/frame.css - server replied: Not Found",
"id": 7,
"url": "http://www.hpenterprisesecurity.com/vulncat/en/vulncat/css/frame.css"
}
ResourceError: {
"errorCode": 2,
"errorString": "Connection closed",
"id": 9,
"url": "http://www.fortifysoftware.com/images/gui/maincontent.level3.h1.bg.png"
}
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html (HTTP 200)
---------- TITLE:
A Taxonomy of Coding Errors that Affect Security
[info] [phantom] Step anonymous 2/4: done in 770ms.
[info] [phantom] Step _step 3/5 http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html (HTTP 200)
[info] [phantom] Step _step 3/5: done in 770ms.
[info] [phantom] wait() finished waiting for 5000ms.
[info] [phantom] Step _step 4/5 http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html (HTTP 200)
[debug] [phantom] Mouse event 'mousedown' on selector: xpath selector: //*[#id="theContentCenter"]/div/p/a[1]/strong[contains(text(),"Expand")]
CasperError: Cannot dispatch mousedown event on nonexistent selector: xpath selector: //*[#id="theContentCenter"]/div/p/a[1]/strong[contains(text(),"Expand")]
/usr/lib/node_modules/casperjs/modules/casper.js:1355 in mouseEvent
/usr/lib/node_modules/casperjs/modules/casper.js:462 in click
/usr/lib/node_modules/casperjs/modules/casper.js:1793 in _step
/usr/lib/node_modules/casperjs/modules/casper.js:1553 in runStep
/usr/lib/node_modules/casperjs/modules/casper.js:399 in checkStep
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.
Related
When i executing script it will launch URL"www.google.com" in emulator and rest of line are not executing.
"Please suggest me the solution" Is this way to write elements?
Environment details:
JDK 1.8
Appium v1.17
Node js v12.18
Andriod stuido v4
Feature file:
Feature: Testing Mobile
Scenario: launch chrome in appium
* configure driver =
"""
{
type: 'android',
webDriverPath : "/wd/hub",
start: true,
httpConfig : { readTimeout: 120000 }
}
"""
* def desiredConfig =
"""
{
"newCommandTimeout" : 300,
"platformVersion" : "10.0",
"platformName" : "Android",
"connectHardwareKeyboard" : true,
"deviceName" : "emulator-5554",
"avd" : "Pixel_2_API_29",
"automationName" : "UiAutomator2",
"browserName" : "Chrome" ,
"chromedriverExecutable" : "C:/Users/abc/Downloads/chromedriver_win32_2/chromedriver.exe"
}
"""
* driver { webDriverSession: { desiredCapabilities : "#(desiredConfig)"} }
* driver 'http://google.com'
And delay(4000)
* driver click("//a[text()='Images']")
# driver.input("//input[#name='q']", 'karate dsl')
Logs in console:
10:31:16.654 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [HTTP] --> POST /wd/hub
/session/3b12fd81-db3b-421e-8218-b94c1ed331b5/element
10:31:16.695 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [HTTP] {"using":"xpath","value":"//a[text()
='Images']"}
10:31:16.698 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [MJSONWP (3b12fd81)] Calling AppiumDrive
r.findElement() with args: ["xpath","//a[text()='Images']","3b12fd81-db3b-421e-8218-b94c1ed331b5"]
10:31:16.699 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [BaseDriver] Valid locator strategies fo
r this request: xpath, id, class name, accessibility id, -android uiautomator
10:31:16.702 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [BaseDriver] Waiting up to 0 ms for cond
ition
10:31:16.703 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [WD Proxy] Matched '/element' to command
name 'findElement'
10:31:16.706 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [WD Proxy] Proxying [POST /element] to [
POST http://127.0.0.1:8203/wd/hub/session/600582cc-a05b-422e-b886-7daeff02de45/element] with body: {"strategy":"xpath","selector":"//a[text()='Images']","context":"","multiple":false}
10:31:17.466 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [WD Proxy] Got response with status 404: {"sessi
onId":"600582cc-a05b-422e-b886-7daeff02de45","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:102)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:72)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:51)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerCon...
10:31:17.467 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [W3C] Matched W3C error code 'no such el
ement' to NoSuchElementError
10:31:17.474 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - response time in milliseconds: 823.75
5 < 500
5 < Connection: keep-alive
5 < Content-Length: 164
5 < Content-Type: application/json; charset=utf-8
5 < Date: Wed, 01 Jul 2020 05:01:17 GMT
5 < ETag: W/"a4-/qNMwkKiq6QWZf9aZdImFcg10wM"
5 < Vary: X-HTTP-Method-Override
5 < X-Powered-By: Express
{"status":7,"value":{"message":"An element could not be located on the page using the given search parameters."},"sessionId":"3b12fd81-db3b-421e-8218-b94c1ed331b5"}
10:31:17.478 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [MJSONWP (3b12fd81)] Encountered interna
l error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
10:31:17.484 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [MJSONWP (3b12fd81)] at AndroidUiaut
omator2Driver.findElOrEls (C:\Users\M1058955\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11)
10:31:17.484 [ForkJoinPool-1-worker-1] WARN com.intuit.karate - http response code: 500, response: {"sessionId":"3b12fd81-db3b-421e-8218-b94c1ed331b5","value":{"message":"An element could not be located on the page using the given search parameters."},"status":7}, request: [method: POST, responseTime: 823.7536, body: {"using":"xpath","value":"//a[text()='Images']"}]
10:31:17.484 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [HTTP] <-- POST /wd/hub/session/3b12fd81-db
3b-421e-8218-b94c1ed331b5/element 500 819 ms - 164
10:31:17.484 [ForkJoinPool-1-worker-1] WARN c.i.k.driver.android_1593579654225 - locator failed, will retry once: {"sessionId":"3b12fd81-db3b-421e-8218-b94c1ed331b5","value":{"message":"An element could not be located on the page using the given search parameters."},"status":7}
10:31:17.485 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [HTTP]
10:31:20.490 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - request:
6 > POST http://localhost:50636/wd/hub/session/3b12fd81-db3b-421e-8218-b94c1ed331b5/element
6 > Accept-Encoding: gzip,deflate
6 > Connection: Keep-Alive
6 > Content-Length: 48
6 > Content-Type: application/json; charset=UTF-8
6 > Host: localhost:50636
6 > User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_181)
{"using":"xpath","value":"//a[text()='Images']"}
10:31:20.531 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [HTTP] --> POST /wd/hub
/session/3b12fd81-db3b-421e-8218-b94c1ed331b5/element
10:31:20.532 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [HTTP] {"using":"xpath","value":"//a[text()
='Images']"}
10:31:20.533 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [MJSONWP (3b12fd81)] Calling AppiumDrive
r.findElement() with args: ["xpath","//a[text()='Images']","3b12fd81-db3b-421e-8218-b94c1ed331b5"]
10:31:20.534 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [BaseDriver] Valid locator strategies fo
r this request: xpath, id, class name, accessibility id, -android uiautomator
10:31:20.535 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [BaseDriver] Waiting up to 0 ms for cond
ition
10:31:20.536 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [WD Proxy] Matched '/element' to command
name 'findElement'
10:31:20.536 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [WD Proxy] Proxying [POST /element] to [
POST http://127.0.0.1:8203/wd/hub/session/600582cc-a05b-422e-b886-7daeff02de45/element] with body: {"strategy":"xpath","selector":"//a[text()='Images']","context":"","multiple":false}
10:31:21.026 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [WD Proxy] Got response with status 404: {"sessi
onId":"600582cc-a05b-422e-b886-7daeff02de45","value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters","stacktrace":"io.appium.uiautomator2.common.exceptions.ElementNotFoundException: An element could not be located on the page using the given search parameters\n\tat io.appium.uiautomator2.handler.FindElement.findElement(FindElement.java:102)\n\tat io.appium.uiautomator2.handler.FindElement.safeHandle(FindElement.java:72)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:38)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:252)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:242)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:51)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerCon...
10:31:21.027 [android_1593579654225] DEBUG c.i.k.driver.android_1593579654225 - [debug] [W3C] Matched W3C error code 'no such el
ement' to NoSuchElementError
10:31:21.028 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - response time in milliseconds: 498.60
6 < 500
can you please try karate version 0.9.6.RC3 ?, maybe based on you location Images locator might be changing?
xpath
Given driver 'https://www.google.com'
Then waitForUrl('https://www.google.com')
And click("//a[text()='Images']")
And input("//input[#name='q']", 'karate dsl')
should work with this version of karate and appium 1.17.1.
I'm diving into functional testing and attempting to get a few simple tasks working. The app is built in ReactJS and I've decided to use Phantom/Casper. The problem is that even the most basic tasks fail.
In short, is there a trick for testing React apps with Phantom/Casper?
I've installed Phantom (v.2.1.1) and Casper (v1.1.0-beta5). As a first attempt I created a simple script to capture an image:
capture.js
var casper = require('casper').create({
viewportSize: {
width: 1024,
height: 768
},
verbose: true,
logLevel: "debug"
});
casper.start('http://localhost:9494', function() {
console.log("page loaded");
});
casper.then(function() {
this.capture('img.png');
});
});
casper.run();
Then run the script:
> casperjs capture.js
Viewing localhost:9494 in my browser pulls up the app as it should. But the resulting capture() image is a blank screen.
I've also tried adding a wait(), waitForSelector() and waitForResource() to no avail.
Here's the output in the console:
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://localhost:9494/, HTTP GET
[debug] [phantom] Navigation requested: url=http://localhost:9494/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://localhost:9494/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2 http://localhost:9494/ (HTTP 200) page loaded
[debug] [phantom] Capturing page to /path/to/img.png
[info] [phantom] Capture saved to /path/to/img.png
[info] [phantom] Step anonymous 2/2: done in 848ms.
[info] [phantom] Done 2 steps in 848ms
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "about:blank"
You need to add the babel-polyfill NPM package to your project (or any other version of the polyfill) and then in your main index.js(x) entry point for your app, include this line at the top:
import 'babel-polyfill';
We were having the exact same issue you are experiencing and this fixed it for us.
We had tried injecting the babel polyfill as part of the Casper test suite, but it was not working.
Not sure how you did the waiting. Make sure your capture is in the wait callback. I usually use code like this and it often happens that you need to adjust the waiting time to see results.
3 seconds is usually enough to crawl public websites, that's how I use it.
casper.then(function() {
this.wait(3000, function() {
this.capture('foo.jpg', undefined,
{
format: 'jpg',
quality: 75
});
});
});
I'm stuck on a page which returns 4 lines like this and then hangs up:
[debug] [phantom] opening url: https://xxx, HTTP GET
[debug] [phantom] Navigation requested: url=https://xxx, type=Other, willNavigate=true, isMainFrame=true
[info] [phantom] Step anonymous 3/6: done in 170ms.
[debug] [phantom] url changed to "https://xxx"
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
I launch the command this way, since I read about several ssl related bugs, and it works for the whole website xxx:
casperjs --ignore-ssl-errors=true --ssl-protocol=any script.js
My code is not nested since it's generated by my own class. However it's quite simple:
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7');
casper.start().then(function() {
this.open('https://xxx', {
headers: {
'Accept': 'text/html'
}
});
});
casper.then(function () {
this.viewport(1920, 1080);
});
casper.wait(
3000,
function () {
this.echo('timeout occured');
}
);
casper.then(function() {
this.capture('capture.png', {
top: 0,
left: 0,
width: 1920,
height: 1080
});
});
casper.run();
I need a hint by an expert, unluckily I'm not. Thank you in advance
Fixed in phantomjs 1.9.8, dont trust apt-get regular source (1.9.0-1) and guides around. Don't use 2.00 if you coupled it with casperjs, since is not supported.
Instructions for UBUNTU, for CENTOS replace apt-get with yum.
sudo apt-get update
apt-get install python
apt-get install ttf-mscorefonts-installer
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev
export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
Phantomjs version - 1.9.7
Casperjs version - 1.1.0-beta3
This is the code
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
});
casper.start('https://www.gmail.com', function() {
casper.wait(3000, function() {
this.capture('gmail.png');
});
});
casper.run(function() {
this.exit();
});
The logs on Windows show
casperjs --ssl-protocol=any --ignore-ssl-errors=true login.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.gmail.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.gmail.com/, type=Other, willNavigate=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail: https://www.gmail.com/
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2: done in 349ms.
[info] [phantom] Step _step 3/3: done in 371ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to C:/Users/username/Desktop/gmail.png
[info] [phantom] Capture saved to C:/Users/username/Desktop/gmail.png
[info] [phantom] Done 3 steps in 3408ms
On OSX it shows the following
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.gmail.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.gmail.com/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://mail.google.com/mail/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1"
[debug] [phantom] Navigation requested: url=https://accounts.youtube.com/accounts/CheckConnection?pmpo=https://accounts.google.com&v=-320444755×tamp=1420230909413, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2 https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1 (HTTP 200)
[info] [phantom] Step anonymous 2/2: done in 1398ms.
[info] [phantom] Step _step 3/3 https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1 (HTTP 200)
[info] [phantom] Step _step 3/3: done in 1418ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to /Users/username/code/casperjs/gmail.png
[info] [phantom] Capture saved to /Users/username/code/casperjs/gmail.png
[info] [phantom] Done 3 steps in 4511ms
The code is the same on both platforms, I have tried various combinations of --ignore-ssl-errors etc with no luck. Any suggestions?
Based on Artjom B.'s suggestions, I have updated the code like this -
var webPage = require('webpage');
var page = webPage.create();
var casper = require('casper').create({
verbose: true,
logLevel: 'debug',
pageSettings: {
userAgent: 'Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1'
}
});
casper.on('resource.error', function(resource) {
this.echo('Error: ' +msg, 'ERROR'); });
casper.on("page.error", function(msg, trace) {
this.echo("Error: " + msg, "ERROR");
});
page.onResourceTimeout = function(request) {
console.log('Response (#' + request.id + '): ' + JSON.stringify(request));
};
casper.on("remote.message", function(msg, trace) {
this.echo("Error: " + msg, "ERROR");
});
casper.start('https://www.gmail.com', function() {
casper.wait(3000, function() {
this.capture('gmail.png');
});
});
casper.run(function() {
this.exit();
});
This gives the same result -
C:\Users\username\Desktop>casperjs --ssl-protocol=any --ignore-ssl-errors=true pt-login.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: https://www.gmail.com/, HTTP GET
[debug] [phantom] Navigation requested: url=https://www.gmail.com/, type=Other, willNavigate=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail: https://www.gmail.com/
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2: done in 338ms.
[info] [phantom] Step _step 3/3: done in 361ms.
[info] [phantom] wait() finished waiting for 3000ms.
[debug] [phantom] Capturing page to C:/Users/username/Desktop/gmail.png
[info] [phantom] Capture saved to C:/Users/username/Desktop/gmail.png
[info] [phantom] Done 3 steps in 3462ms
I'm trying to load the following webpage with casperjs/phantomjs http://m.10bet.com/#leage_panel#10096.
Therefore I wrote the following simple casper script:
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
if( casper.cli.args.length != 1 )
casper.echo('No URL as arguments given. Exiting.\n').exit();
var id = casper.cli.args[0]
casper.start( 'http://m.10bet.com/#leage_panel#' + id, function() {
casper.waitForResource("http://m.10bet.com/pagemethods.aspx/UpdateEvents", function() {
this.echo(casper.getPageContent())
}, function(){}, function(){}, 10000 );
});
casper.run(function() {
this.echo('Done.').exit();
});
So, I'm waiting for the last resource to be loaded which is in this case "http://m.10bet.com/pagemethods.aspx/UpdateEvents". I checked this with the chrome developer tools. Subsequently I want to output the rendered html on the console.
However, but instead of the html I get a in my opinion very strange error:
solaris:js_loaders Tom$ casperjs 10bet_loader.js 10096
2014-01-03 17:31:36.545 phantomjs[8733:130b] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://m.10bet.com/#leage_panel#10096, HTTP GET
[debug] [phantom] Navigation requested: url=http://m.10bet.com/#leage_panel#10096, type=Other, lock=true, isMainFrame=true
[debug] [phantom] url changed to "http://m.10bet.com/#leage_panel#10096"
[debug] [phantom] Navigation requested: url=http://m.10bet.com/#leage_panel#10096, type=Reload, lock=true, isMainFrame=true
[warning] [phantom] Loading resource failed with status=fail (HTTP 200): http://m.10bet.com/#leage_panel#10096
[debug] [phantom] Successfully injected Casper client-side utilities
[debug] [phantom] url changed to "http://m.10bet.com/#leage_panel#10096"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step 2/2 http://m.10bet.com/#leage_panel#10096 (HTTP 200)
[info] [phantom] Step 2/2: done in 761ms.
[info] [phantom] Step 3/3 http://m.10bet.com/#leage_panel#10096 (HTTP 200)
[info] [phantom] Step 3/3: done in 771ms.
[warning] [phantom] Casper.waitFor() timeout
[info] [phantom] Done 3 steps in 790ms
Done.
solaris:js_loaders Tom$
As you can see from the log the error "Loading resource failed with status=fail (HTTP 200): http://m.10bet.com/#leage_panel#10096" gives a http 200 ok but failed. Eventually the webpage is not loaded or printed on the console. So I'm wondering what is going wrong here?
Usage:
casperjs stackoverflow.js --idEvent=10096
Code:
var casper = require('casper').create ({
waitTimeout: 15000,
stepTimeout: 15000,
verbose: true,
viewportSize: {
width: 1024,
height: 768
},
pageSettings: {
"userAgent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.10 (KHTML, like Gecko) Chrome/23.0.1262.0 Safari/537.10',
"loadImages": false,
"loadPlugins": false,
"webSecurityEnabled": false,
"ignoreSslErrors": true
},
onWaitTimeout: function() {
casper.echo('Wait TimeOut Occured');
},
onStepTimeout: function() {
casper.echo('Step TimeOut Occured');
}
});
//vars
var idEvent = casper.cli.get('idEvent');
// start
casper.start();
// check args
casper.then(function() {
if (!idEvent) {
//usage check
this.echo('Invalid usage: Must supply Event Id');
casper.exit();
}
});
casper.thenOpen('http://m.10bet.com/#leage_panel#' + idEvent, function() {
casper.waitForResource('http://m.10bet.com/pagemethods.aspx/UpdateEvents', function() {
//casper.waitForSelector('#league_block', function() {
}, function then() { //selector found
this.echo(casper.getPageContent());
casper.exit();
}, function timeout() { //selector not found
this.echo("Timeout On Selector...Exiting").exit();
});
});
// executes
casper.run();
Does your arguments work in other scripts? I'm curious because the documentation shows that arguments are referenced in this way.
casper.echo(casper.cli.has(0));
I'm wondering if maybe this is the issue?