Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
b1e9bede
...
b1e9bede2f63a7bc9b9946d806d66b3588b00d0a
authored
2011-12-30 13:22:34 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper.getElementBounds()
1 parent
e3d59675
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
8 deletions
modules/casper.js
modules/casper.js
View file @
b1e9bed
...
...
@@ -151,8 +151,8 @@ Casper.prototype = {
var
previousClipRect
;
targetFile
=
fs
.
absolute
(
targetFile
);
if
(
clipRect
)
{
if
(
!
utils
.
is
Type
(
clipRect
,
"object"
))
{
throw
new
Error
(
"clipRect must be a
n Object instance
."
);
if
(
!
utils
.
is
ClipRect
(
clipRect
))
{
throw
new
Error
(
"clipRect must be a
valid ClipRect object
."
);
}
previousClipRect
=
this
.
page
.
clipRect
;
this
.
page
.
clipRect
=
clipRect
;
...
...
@@ -177,9 +177,7 @@ Casper.prototype = {
* @return Casper
*/
captureSelector
:
function
(
targetFile
,
selector
)
{
return
this
.
capture
(
targetFile
,
this
.
evaluate
(
function
(
selector
)
{
return
__utils__
.
getElementBounds
();
},
{
selector
:
selector
}));
return
this
.
capture
(
targetFile
,
this
.
getElementBounds
(
selector
));
},
/**
...
...
@@ -513,6 +511,25 @@ Casper.prototype = {
},
/**
* Retrieves boundaries for a DOM element matching the provided CSS3 selector.
*
* @param String selector A CSS3 selector
* @return Object
*/
getElementBounds
:
function
(
selector
)
{
if
(
!
this
.
exists
(
selector
))
{
throw
new
Error
(
"No element matching selector found: "
+
selector
);
}
var
clipRect
=
this
.
evaluate
(
function
(
selector
)
{
return
__utils__
.
getElementBounds
();
},
{
selector
:
selector
});
if
(
!
utils
.
isClipRect
(
clipRect
))
{
this
.
log
(
'Could not fetch boundaries for element matching selector: '
+
selector
,
"error"
);
}
return
clipRect
;
},
/**
* Retrieves global variable.
*
* @param String name The name of the global variable to retrieve
...
...
@@ -594,9 +611,7 @@ Casper.prototype = {
* @return Casper
*/
mouseClick
:
function
(
selector
)
{
var
bounds
=
this
.
evaluate
(
function
(
selector
)
{
return
__utils__
.
getElementBounds
(
selector
);
},
{
selector
:
selector
});
var
bounds
=
this
.
getElementBounds
(
selector
);
if
(
utils
.
isClipRect
(
bounds
))
{
var
x
=
bounds
.
left
+
Math
.
floor
(
bounds
.
width
/
2
);
var
y
=
bounds
.
top
+
Math
.
floor
(
bounds
.
height
/
2
);
...
...
Please
register
or
sign in
to post a comment