jeanphix / Ghost.py

Webkit based scriptable web browser for python.
http://ghost-py.readthedocs.org/en/latest/
2.76k stars 380 forks source link

How to wait (while the content is playing)? #287

Open hsch0 opened 8 years ago

hsch0 commented 8 years ago

ok, I made a program which connects to takes www.forecast.io, fills in the city name click on the animation. then I create a png snapshot. But when the animation started I would like to make a couple of snapshots (e.g. each second) for the different forecast images. the python time.sleep() doesn't work, it seems to pause the complete website..

import ghost
import time

g = ghost.Ghost()
with g.start(wait_timeout=20) as session:
    page, extra_resources = session.open("http://forecast.io/#/f/51.5171,-0.1062")
    if page.http_status == 200:
        print("Good!")
        #print session.content
    # Waits for form search field
    session.wait_for_selector('.location_field')
    session.wait_for_selector('.forecast button')

    session.evaluate("document.getElementsByClassName('location_field')[0].value='Berlin';")
    session.click(".forecast button")
    session.click(".label")
    session.capture_to('forecast.png')
    session.click(".c")
    session.click(".refresh")
    session.wait_for_text("Rome")
    session.capture_to('forecast2.png')
    session.click(".load_animation_small")
    session.wait_for_text("Tomorrow", timeout=120)
    session.capture_to('forecast3.png')
    session.click(".level2")
    session.click(".load_animation_small")
    session.wait_for_text("Tomorrow", timeout=120)
    session.capture_to('forecast4.png')
    time.sleep(1)
    session.capture_to('forecast5.png')
    time.sleep(1)
    session.capture_to('forecast6.png')
naclander commented 8 years ago

Does session.sleep(1)not do what you want?