0

I am writing a selenium script to perform form fills at a certain time of day.

I currently have the form fills scheduled with Python's schedule module however this uses my system time. The issue is my system time is not synced with the websites server time. Fortunately, the website has a live clock in the page.

I inspected the clock element which is as follows:

<span>The Time is: <b class="jquery_server_clock" dfc="pv">5:24:59 PM</b></span>

What I am trying to do is monitor the live clock on the website and when it hits a certain time perform an action - I was thinking with a 'while loop'.

Something like:

while true:
    t = "jquery_server_clock"
    if t = "6:00:00 PM"
        driver.find_element_by_name("submit").click()

I can't seem to get the clock time into a variable to monitor at this point. After I get that I'm sure I could get the while loop working.

Thank you for the help!

jmarusiak
  • 145
  • 2
  • 13
  • Possible duplicate of [How to get current time in Python?](https://stackoverflow.com/questions/415511/how-to-get-current-time-in-python) – Octopusghost Jun 01 '18 at 00:54
  • The issue with this is it gets my systems time. Not the time from the website. Unfortunately, my systems time and the websites time is not in sync. By monitoring the live clock on the website I can be sure it is clicked at the right time. – jmarusiak Jun 01 '18 at 00:59
  • This can be simplified if you just find the webserver's timezone. Add or subtract the difference between your timezone and the webserver's time zone and adjust your trigger time accordingly. Continuously monitoring the live clock on the page just seems a little wasteful – GPT14 Jun 01 '18 at 07:55

2 Answers2

1

In a while loop, your going to have to get the span that contains the time, for example like so.

time_element = driver.find_elements_by_class_name("jquery_server_clock");

Then you can get the time as a string

time_element.get_attribute('text')

Then you could convert this into a DateTime object and then simply check if the time is more than or equal to a DateTime of 6 o'clock.

SillySam
  • 98
  • 7
0

As per the HTML you have provided, to monitor the live clock on the website and execute your @Tests at a certain time e.g. 6:00:00 PM you can use the following solution:

myElem = driver.find_element_by_xpath("//span[contains(.,'The Time is:')]").get_attribute("innerHTML")
if "6:00:00 PM" in myElem
    driver.find_element_by_name("submit").click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352