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
13f2ed24
...
13f2ed24efad14e07289907ca7dda2f7ff3b96c5
authored
2011-12-07 12:43:48 -0700
by
Solomon White
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
add visible, wait while/until visible
1 parent
58fc30eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
2 deletions
casper.js
casper.js
View file @
13f2ed2
...
...
@@ -402,6 +402,22 @@
},
/**
* Checks if an element matching the provided CSS3 selector is visible
* current page DOM by checking that offsetWidth and offsetHeight are
* both non-zero.
*
* @param String selector A CSS3 selector
* @return Boolean
*/
visible
:
function
(
selector
)
{
return
this
.
evaluate
(
function
()
{
return
__utils__
.
visible
(
__casper_params__
.
selector
);
},
{
selector
:
selector
});
},
/**
* Exits phantom.
*
* @param Number status Status
...
...
@@ -919,8 +935,8 @@
},
/**
* Waits until an element matching the provided CSS3 selector does not
exist in
* remote DOM to process a next step.
* Waits until an element matching the provided CSS3 selector does not
*
exist in the
remote DOM to process a next step.
*
* @param String selector A CSS3 selector
* @param Function then The next step to perform (optional)
...
...
@@ -933,6 +949,40 @@
return
this
.
waitFor
(
function
(
self
)
{
return
!
self
.
exists
(
selector
);
},
then
,
onTimeout
,
timeout
);
},
/**
* Waits until an element matching the provided CSS3 selector is
* visible in the remote DOM to process a next step.
*
* @param String selector A CSS3 selector
* @param Function then The next step to perform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @param Number timeout The max amount of time to wait, in milliseconds (optional)
* @return Casper
*/
waitUntilVisible
:
function
(
selector
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
self
.
visible
(
selector
);
},
then
,
onTimeout
,
timeout
);
},
/**
* Waits until an element matching the provided CSS3 selector is no
* longer visible in remote DOM to process a next step.
*
* @param String selector A CSS3 selector
* @param Function then The next step to perform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @param Number timeout The max amount of time to wait, in milliseconds (optional)
* @return Casper
*/
waitWhileVisible
:
function
(
selector
,
then
,
onTimeout
,
timeout
)
{
timeout
=
timeout
?
timeout
:
this
.
defaultWaitTimeout
;
return
this
.
waitFor
(
function
(
self
)
{
return
!
self
.
visible
(
selector
);
},
then
,
onTimeout
,
timeout
);
}
};
...
...
@@ -1027,6 +1077,21 @@
};
/**
* Checks if a given DOM element is visible in remote page.
*
* @param String selector CSS3 selector
* @return Boolean
*/
this
.
visible
=
function
(
selector
)
{
try
{
var
el
=
document
.
querySelector
(
selector
);
return
el
&&
el
.
offsetHeight
>
0
&&
el
.
offsetWidth
>
0
;
}
catch
(
e
)
{
return
false
;
}
};
/**
* Fetches innerText within the element(s) matching a given CSS3
* selector.
*
...
...
Please
register
or
sign in
to post a comment