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
dd84d1ab
...
dd84d1ab1d826a0ed09f3310d961c70a663dc9c8
authored
2012-05-12 11:42:27 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added BC way to use XPath selectors in clientutils
1 parent
c3db0ced
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
3 deletions
modules/clientutils.js
modules/clientutils.js
View file @
dd84d1a
...
...
@@ -47,6 +47,7 @@
-
1
,
26
,
27
,
28
,
29
,
30
,
31
,
32
,
33
,
34
,
35
,
36
,
37
,
38
,
39
,
40
,
41
,
42
,
43
,
44
,
45
,
46
,
47
,
48
,
49
,
50
,
51
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
);
var
SUPPORTED_SELECTOR_TYPES
=
[
'css'
,
'xpath'
];
/**
* Clicks on the DOM element behind the provided selector.
...
...
@@ -241,10 +242,15 @@
* @return NodeList|undefined
*/
this
.
findAll
=
function
findAll
(
selector
)
{
var
pSelector
=
this
.
processSelector
(
selector
);
try
{
return
document
.
querySelectorAll
(
selector
);
if
(
pSelector
.
type
===
'xpath'
)
{
return
this
.
getElementsByXPath
(
pSelector
.
path
);
}
else
{
return
document
.
querySelectorAll
(
pSelector
.
path
);
}
}
catch
(
e
)
{
this
.
log
(
'findAll(): invalid selector provided "'
+
selector
+
'":'
+
e
,
"error"
);
this
.
log
(
'findAll(): invalid selector provided "'
+
pSelector
.
toString
()
+
'":'
+
e
,
"error"
);
}
};
...
...
@@ -255,8 +261,13 @@
* @return HTMLElement|undefined
*/
this
.
findOne
=
function
findOne
(
selector
)
{
var
pSelector
=
this
.
processSelector
(
selector
);
try
{
return
document
.
querySelector
(
selector
);
if
(
pSelector
.
type
===
'xpath'
)
{
return
this
.
getElementByXPath
(
pSelector
.
path
);
}
else
{
return
document
.
querySelector
(
pSelector
.
path
);
}
}
catch
(
e
)
{
this
.
log
(
'findOne(): invalid selector provided "'
+
selector
+
'":'
+
e
,
"errors"
);
}
...
...
@@ -374,6 +385,32 @@
console
.
log
(
"[casper:"
+
(
level
||
"debug"
)
+
"] "
+
message
);
};
this
.
processSelector
=
function
processSelector
(
selector
)
{
var
selectorObject
=
{
toString
:
function
toString
()
{
return
this
.
type
+
' selector: '
+
this
.
selector
;
}
};
if
(
typeof
selector
===
"string"
)
{
// defaults to CSS selector
selectorObject
.
type
=
"css"
;
selectorObject
.
path
=
selector
;
return
selectorObject
;
}
else
if
(
typeof
selector
===
"object"
)
{
// validation
if
(
!
selector
.
hasOwnProperty
(
'type'
)
||
!
selector
.
hasOwnProperty
(
'path'
))
{
throw
new
Error
(
"Incomplete selector object"
);
}
else
if
(
SUPPORTED_SELECTOR_TYPES
.
indexOf
(
selector
.
type
)
===
-
1
)
{
throw
new
Error
(
"Unsupported selector type: "
+
selector
.
type
);
}
if
(
!
selector
.
hasOwnProperty
(
'toString'
))
{
selector
.
toString
=
selectorObject
.
toString
;
}
return
selector
;
}
throw
new
Error
(
"Unsupported selector type: "
+
typeof
selector
);
};
/**
* Sets a field (or a set of fields) value. Fails silently, but log
* error messages.
...
...
Please
register
or
sign in
to post a comment