waitForPageToLoad doesn't wait

Here is my script:

{
“Name”: “Try Kantu Command”,
“CreationDate”: “2019-11-3”,
“Commands”: [
{
“Command”: “waitForPageToLoad”,
“Target”: “15000”,
“Value”: “”
}
]
}

I manually open Firefox to some page, for example “https://ui.vision/rpa/docs/selenium-ide/waitforpagetoload”. Then, in Kantu, I click Play Macro. What I see is no 15 second wait. I don’t think there is any page load event happening. So, what I thought I would see is a 15 second countdown then a timeout error. But instead, after playing the script twice, I see this in the log:

  • [status] Playing macro Try Kantu Command
  • [info] Executing: | waitForPageToLoad | 15000 | |
  • [info] Macro completed (Runtime 0.47s)
  • [status] Playing macro Try Kantu Command
  • [info] Executing: | waitForPageToLoad | 15000 | |
  • [info] Macro completed (Runtime 0.46s)

Looks like instead of waiting for a page load event that should never happen, the whole macro completes in less than half a second.

Is there something in configuration I need to set?

In your macro, there is no command that triggers a page load started event (e. g. OPEN does this, or a click on something that opens a new page). And without a page load start event, waitForPageToLoad has nothing to do (as it waits for page load completed event).

If you want to wait in such a case, I recommend to use the XClick (Image for which to wait for) command. In this case XClick waits until the image shows up - or the timeout time is reached.

In your macro, there is no command that triggers a page load started event (e. g. OPEN does this, or a click on something that opens a new page). And without a page load start event, waitForPageToLoad has nothing to do (as it waits for page load completed event).

Yes, I see that you understand the point of my macro, there is nothing to trigger a page load event.

But now you explained something new to me. Let me check if I understand by restating using different words: ‘waitForPageToLoad’ will not wait for anything unless there is a page load started event. Only after detecting that a page load start event occurred will ‘waitForPageToLoad’ wait until timeout or until a page load complete event occurs.

If you want to wait in such a case, I recommend to use the XClick (Image for which to wait for) command. In this case XClick waits until the image shows up - or the timeout time is reached.

I made two scripts to check my understanding:

{
“Name”: “Try 1”,
“CreationDate”: “2019-11-4”,
“Commands”: [
{
“Command”: “open”,
“Target”: “https://news.google.com/?hl=en-US&gl=US&ceid=US:en”,
“Value”: “”
}
]
}

{
“Name”: “Try 2”,
“CreationDate”: “2019-11-4”,
“Commands”: [
{
“Command”: “open”,
“Target”: “https://news.google.com/?hl=en-US&gl=US&ceid=US:en”,
“Value”: “”
},
{
“Command”: “waitForPageToLoad”,
“Target”: “15000”,
“Value”: “”
}
]
}

Here is the log when I run the two scripts:
[status] Playing macro Try 1
[info] Executing: | open | https://news.google.com/?hl=en-US&gl=US&ceid=US:en | |
[info] Macro completed (Runtime 3.00s)
[status] Playing macro Try 1
[info] Executing: | open | https://news.google.com/?hl=en-US&gl=US&ceid=US:en | |
[info] Macro completed (Runtime 2.87s)
[status] Playing macro Try 1
[info] Executing: | open | https://news.google.com/?hl=en-US&gl=US&ceid=US:en | |
[info] Macro completed (Runtime 4.09s)
[status] Playing macro Try 2
[info] Executing: | open | https://news.google.com/?hl=en-US&gl=US&ceid=US:en | |
[info] Executing: | waitForPageToLoad | 15000 | |
[info] Macro completed (Runtime 3.31s)
[status] Playing macro Try 2
[info] Executing: | open | https://news.google.com/?hl=en-US&gl=US&ceid=US:en | |
[info] Executing: | waitForPageToLoad | 15000 | |
[info] Macro completed (Runtime 3.21s)
[status] Playing macro Try 2
[info] Executing: | open | https://news.google.com/?hl=en-US&gl=US&ceid=US:en | |
[info] Executing: | waitForPageToLoad | 15000 | |
[info] Macro completed (Runtime 3.01s)

So, I don’t know because Try 1 and Try 2 have very close average times of 3.32 and 3.18. I was hoping to see that waitForPageToLoad should slow down the script since waitForPageToLoad is going to wait until the page finishes loading before going on. But if anything, waitForPageToLoad sped up the script because the average time is very slightly shorter. But the difference is almost nothing and might be explained with the randomness of page load times.

I probably picked a bad test URL. And/or I still don’t understand what waitForPageToLoad is supposed to do.

Normally you do not need waitForPageToLoad at all. It is more of an old Selenium IDE command that is really needed in UI Vision, since it waits automatically for a page to load.

Only when this fails do you need it, or use XClick (Image for which to wait for) as admin suggested.

Now I think I’m starting to get it. waitForPageToLoad has been deprecated and no longer does anything. Legacy scripts are not broken because it will not generate an error.

In case of Open generating multiple page loads, XClick will wait for an image to become visible which is good proof that a page completed loading.

Sorry it took me so long.

===

The image on the page for which I need to wait is a link that I don’t want to click. So, I can use

XClick | (image) | #right
XType | ${key_esc}

Or maybe better is to use

XMove | (image) |

because XMove does not generate a click in the first place.

Oh, now I think I see even better: If I don’t want a mouse click to verify an image has become present, I should use visualVerify.

Thank you, admin and Timo for your recommendations to use XClick, which lead me not only to XClick but also to the related XMove and visualVerify. These enabled me get my script working without using pause for 10 seconds here and there. My script sped up from a half hour to 7 minutes.