Closed quyeticb closed 8 years ago
Before we embark on another one of these quests, I need to see your modified PJSCtrl.js. Because the stock version of MTS has a function called commandWaitForWindowLoad() which handles the wait. That function relies on onLoadFinished from pjs (http://phantomjs.org/api/webpage/handler/on-load-finished.html).
However think about what constitutes a completely loaded page. Is a page completely loaded when the HTML, JS and images are loaded? For most pages that is ok, but many pages use dynamically fetched content (Ajax) and there is no way to account for that logic to finish processing in a general way.
PM me your PJSCtrl.js
@quyeticb did you resolve the issue, can i go ahead and close?
I can't solved it. Wait suggest from you
Then please send me your modified PJSCtrl.js.
If PJSCtrl.js still invokes the original logic then here is an example of logic you could implement to wait for AJAX content to finish loading:
$timeout = 30; //in seconds
$selector = "a.one:nth-of-type(2)"; //selector you wish to click
$tTime = time() + $timeout;
$pageReady = null;
while($pageReady === null) {
$sExist = $windowObj->getSelectorExists($selector);
if ($sExist === true) {
$pageReady = true;
} elseif (time() > $tTime) {
//failed to get ready before timeout
$pageReady = false;
}
}
if ($pageReady === false) {
//the selector did not load in time. Exception or other logic to handle this condition...
throw new \Exception("Selector: " . $selector . ", did not load in: " . $timeout . " seconds");
} else {
//selector is ready click it
$windowObj->clickElement($selector);
//more logic
}
Did my last suggestion solve your issue?
I have fixed.
Do you mind sharing what the issue was and how your resolved it?
Same as your solved code. Using php try and catch with timeout.
thx
How to wait web page load complete before clickElement(). I'm using sleep(), but sometime page slow to load.