Can we detect if webpage is loaded instead of using wait or exists?

Asked by Jeff Sant

Is there any way to detect page is loaded instead of using wait or exists?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Supposing it is for Windows:

aWin = App("some distinct text from window title")
# this loop waits until a window with that title is available
while not aWin.window():
    wait(1)
aWin.focus() # should bring it to front
aWin.window().highlight(2) # to see it is right

Revision history for this message
Jeff Sant (sant-jeff) said :
#2

i think my question is not clear, now as you have given me a new direction so i have to ask few questions

1. Any way we can discover popup and click on the button using text search instead of picture? (e.g: http://i132.photobucket.com/albums/q1/MiffTheFox/chrome_leave_page.png)

2. Any way we can see if a website such as (www.yahoo.com) is full loaded as everyone has different internet speed so i want to make sure the site is loaded.

3. Any way we can ask Sikuli to go to beginning on any error instead of terminating program and giving error message?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

--1.
Though it is generally possible ( find/click/exists("some-text") ) to search for text, it is currently not recommended (bugs and weak reliability)
In the given case I would use pictures.

--2.
The above snippet (comment #1) at least gives you some certainty, that the webpage in question is reachable and the browser is loading and rendering. wether a webpage is fully loaded can generally only be assured by looking wether everything is there, that should be there (same for Sikuli as for a user). So in the end, you have to look/wait for some images.
idea based on FF 5: in the upper left corner of a tab, there is some spinning wheel while the page is loading. When the page is fully loaded, it is replaced by the pages icon. You might watch this small area (guess 16x16 pixel) for the icon to come up.
These animations are available for other browsers too.

--3.
This generally means to have to implement some looping.
see faq 1437

Revision history for this message
Jeff Sant (sant-jeff) said :
#4

Can we highlight some images as you mentioned the way to highlight application with a particular title?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

Only Region objects have the highlight() feature (and so has Match object inherited).

If you want to highlight an image on the screen, you have to find it and highlight the match:
find(some_image).highlight(3)

Revision history for this message
Jeff Sant (sant-jeff) said :
#6

I have tried to use this, but if there are multiple images, the find highlights an image but the next statement which is of click, it clicks another image instead of the found one.

Do you have any solution with exists?

Thanks

Revision history for this message
Best RaiMan (raimund-hocke) said :
#7

It is always a good idea to post a relevant snippet of code, so it is easier to understand what your doing.

so let me guess a solution ;-)

find(some_image).highlight(2)
click(getLastMatch()) # clicks some_image

Revision history for this message
Jeff Sant (sant-jeff) said :
#8

Thanks RaiMan, that solved my question.

Revision history for this message
sumera (sumera-ather) said :
#9

I am running this thing
openApp("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
type("l", KeyModifier.CTRL)
paste("https://www.google.ca/")

My chrome browser is opened but google is not being loaded. Please help