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
c4582f66
...
c4582f663eaf53b729a80e8af2b77b5077e112b3
authored
2013-05-04 11:57:56 -0600
by
hexid
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add getElementsAttribute(selector) and getElementsInfo(selector)
1 parent
a82c0cbd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
modules/casper.js
modules/clientutils.js
modules/casper.js
View file @
c4582f6
...
...
@@ -897,6 +897,28 @@ Casper.prototype.getElementAttr = function getElementAttr(selector, attribute) {
};
/**
* Retrieves the value of an attribute for each element matching the provided
* DOM CSS3/XPath selector.
*
* @param String selector A DOM CSS3/XPath selector
* @param String attribute The attribute name to lookup
* @return Array
*/
Casper
.
prototype
.
getElementsAttribute
=
Casper
.
prototype
.
getElementsAttr
=
function
getElementsAttr
(
selector
,
attribute
)
{
"use strict"
;
this
.
checkStarted
();
return
this
.
evaluate
(
function
_evaluate
(
selector
,
attribute
)
{
var
ele
=
[];
[].
forEach
.
call
(
__utils__
.
findAll
(
selector
),
function
(
element
)
{
var
e
=
element
.
getAttribute
(
attribute
);
ele
.
push
(
e
);
});
return
ele
;
},
selector
,
attribute
);
}
/**
* Retrieves boundaries for a DOM element matching the provided DOM CSS3/XPath selector.
*
* @param String selector A DOM CSS3/XPath selector
...
...
@@ -935,6 +957,23 @@ Casper.prototype.getElementInfo = function getElementInfo(selector) {
};
/**
* Retrieves information about the nodes matching the provided selector.
*
* @param String|Objects selector CSS3/XPath selector
* @return Array
*/
Casper
.
prototype
.
getElementsInfo
=
function
getElementsInfo
(
selector
)
{
"use strict"
;
this
.
checkStarted
();
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
f
(
"Cannot get information from %s: no elements found."
,
selector
));
}
return
this
.
evaluate
(
function
(
selector
)
{
return
__utils__
.
getElementsInfo
(
selector
);
},
selector
);
};
/**
* Retrieves boundaries for all the DOM elements matching the provided DOM CSS3/XPath selector.
*
* @param String selector A DOM CSS3/XPath selector
...
...
modules/clientutils.js
View file @
c4582f6
...
...
@@ -420,6 +420,35 @@
};
/**
* Retrieves information about the nodes matching the provided selector.
*
* @param String|Object selector CSS3/XPath selector
* @return Array
*/
this
.
getElementsInfo
=
function
getElementsInfo
(
selector
)
{
var
bounds
=
this
.
getElementsBounds
(
selector
);
var
visibility
=
this
.
visible
(
selector
);
return
Array
.
prototype
.
map
.
call
(
this
.
findAll
(
selector
),
function
(
element
,
index
)
{
var
attributes
=
{};
[].
forEach
.
call
(
element
.
attributes
,
function
(
attr
)
{
attributes
[
attr
.
name
.
toLowerCase
()]
=
attr
.
value
;
});
return
{
nodeName
:
element
.
nodeName
.
toLowerCase
(),
attributes
:
attributes
,
tag
:
element
.
outerHTML
,
html
:
element
.
innerHTML
,
text
:
element
.
innerText
,
x
:
bounds
[
index
].
left
,
y
:
bounds
[
index
].
top
,
width
:
bounds
[
index
].
width
,
height
:
bounds
[
index
].
height
,
visible
:
visibility
};
});
};
/**
* Retrieves a single DOM element matching a given XPath expression.
*
* @param String expression The XPath expression
...
...
Please
register
or
sign in
to post a comment