0
votes

i have made a websurfer script with Python and Selenium.

I am making the script so it will do one function, which have a cooldown for 60 seconds, and continue to function number two(without waiting for the 60 seconds cooldown).

I am looking for a solution where i can do task number one, start counting down while going to the next function(which also has a cooldown for 100 seconds), start a timer for this, and looping the hole program(in eternity).

Code:

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys



username = input("Type your username: ")
password = input("Type in your password: ")

#Opening Firefox
driver = webdriver.Firefox()


#Logging in
def login():

    driver.get("http://website.com")
    un = driver.find_element_by_name("username")
    un.send_keys(username)
    pw = driver.find_element_by_name("password")
    pw.send_keys(password)
    login = driver.find_element_by_name("login")
    login.click()


def first():
    driver.get("http://website.com/page1")
    po = driver.find_element_by_id("id_1")
    po.click() #Have to wait 60 sec before i can repeat this step


def second():
    driver.get("http://website.com/page2")
    pt = driver.find_element_by_id("id_2")
    pt.click() #Have to wait 100 sec before i can repeat this step



login()
first()   #I want this
second()  #and this function to repeat themselves until i cancel the script

Is anyone able to help me with a solution to this?

Sorry for the bad explanation.

Any help would be apriciated!

1

1 Answers

1
votes

This was actually quite simple. Added this to import list

Import threading

And added this to my functions:

threading.Timer(60, first).start)