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
71d1e20d
...
71d1e20d45110388fd1ce3b48bbbd6172ffd7074
authored
2012-06-06 04:40:01 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added an optional 'tag' arg to Casper.clickLabel()
1 parent
0e7e2ebc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
docs
modules/casper.js
docs
@
e8cbff91
Subproject commit e
ad2191ceb086cd5665e18a822f72689d90a6c3d
Subproject commit e
8cbff91a0088280b9a352c36e178ea04cf32042
...
...
modules/casper.js
View file @
71d1e20
...
...
@@ -41,7 +41,14 @@ exports.create = function create(options) {
return
new
Casper
(
options
);
};
exports
.
selectXPath
=
function
selectXPath
(
expression
)
{
/**
* Shortcut to build an XPath selector object.
*
* @param String expression The XPath expression
* @return Object
* @see http://casperjs.org/selectors.html
*/
function
selectXPath
(
expression
)
{
return
{
type
:
'xpath'
,
path
:
expression
,
...
...
@@ -49,7 +56,8 @@ exports.selectXPath = function selectXPath(expression) {
return
this
.
type
+
' selector: '
+
this
.
path
;
}
};
};
}
exports
.
selectXPath
=
selectXPath
;
/**
* Main Casper object.
...
...
@@ -296,10 +304,13 @@ Casper.prototype.click = function click(selector) {
* element matching this label will be selected, so use with caution.
*
* @param String label Element innerText value
* @param String tag An element tag name (eg. `a` or `button`) (optional)
* @return Boolean
*/
Casper
.
prototype
.
clickLabel
=
function
clickLabel
(
label
)
{
var
selector
=
exports
.
selectXPath
(
'//*[text()="'
+
label
.
toString
()
+
'"]'
);
Casper
.
prototype
.
clickLabel
=
function
clickLabel
(
label
,
tag
)
{
tag
=
tag
||
"*"
;
var
escapedLabel
=
label
.
toString
().
replace
(
/"/g
,
'\\"'
);
var
selector
=
selectXPath
(
f
(
'//%s[text()="%s"]'
,
tag
,
escapedLabel
));
return
this
.
click
(
selector
);
};
...
...
Please
register
or
sign in
to post a comment