2

I'm new python 3 user.

I have a project web scraping via python 3 which I have to waiting until time will be 08:22:00 PM after login to web target.

I have project and not any problem but I want import only waiting until specific time and continue again.

Do you have any idea or can you show me any code about that for example :

WebDriverWait(driver, 10).until() # for example time=08:22:00 pm continue

thanks

Rai Rz
  • 493
  • 9
  • 22
  • Selenium condition waits for and returns an element, so what is the element in this case? Seems you are waiting just for particular time, so why not wait directly as discussed here https://stackoverflow.com/questions/6579127/delay-a-task-until-certain-time/ ? – timbre timbre Jan 22 '18 at 22:07
  • If you're just scraping, why not just kick off the script at 8:22pm? – MivaScott Jan 22 '18 at 22:27
  • @MivaScott, Because if you trying to login in 8:22 site don't load page if you was not logged – Rai Rz Jan 23 '18 at 07:29

1 Answers1

4

If you look at the API Docs of WebDriverWait it is defined as :

class selenium.webdriver.support.wait.WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None)
Constructor, takes a WebDriver instance and timeout in seconds.

Further the untill method is defined as :

until(method, message='')
Calls the method provided with the driver as an argument until the return value is not False.

So both WebDriverWait constructor and until method is associated with the WebDriver instance which is extensively used to communicate with Browser Clients. Hence WebDriver may not help you.

Having said that different solutions are available through Python.


Solution # 1

You can import the time and datetime module of Python to sleep() in a simple loop as follows :

import datetime
import time

# datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
# The year, month and day arguments are required. tzinfo may be None.
target_time = datetime.datetime(2018, 1, 23, 13, 2, 00)  # 13:02 pm on 23 January 2018
while datetime.datetime.now() < target_time:
    time.sleep(10)
print("It is 13:02 pm, 2018. Resuming Test Execution")

Solution # 2

You can import the Timer object from threading module of Python to induce a timer as follows :

from threading import Timer

def hello():
    print("Hello World")

t = Timer(10.0, hello)
t.start()  # after 30 seconds, "Hello World" will be printed

Trivia

You also use the Event scheduler Class sched which implements a general purpose event scheduler:

class sched.scheduler(timefunc=time.monotonic, delayfunc=time.sleep)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352