【问题标题】:Timer using datetime to do something定时器使用日期时间做某事
【发布时间】:2021-03-22 16:16:24
【问题描述】:

我希望我的脚本在特定的小时、分钟和秒执行某些操作

我已经有一个代码,但我需要它在特定的小时、分钟和秒内完成它应该做的事情

    self.driver.get(link)
    time.sleep(1)
    add_to_cart_button = self.driver.find_element_by_class_name("product-variation")
    add_to_cart_button.click()
    time.sleep(2)
    button = self.driver.find_element_by_class_name("btn btn-solid-primary btn--l YtgjXY")
    button.click()

这是我的代码,谁能帮帮我,我需要button.click() 点击例如 18:01:59

【问题讨论】:

    标签: python selenium time timer


    【解决方案1】:

    你可以这样试试:

    from datetime import datetime, time
    from time import sleep
    
    def wait_start(runTime, action):
        startTime = time(*(map(int, runTime.split(':'))))
        while startTime > datetime.today().time():
            sleep(1)
    
    wait_start('18:01:59', lambda: button.click())
    

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 2012-07-30
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多