代码之家  ›  专栏  ›  技术社区  ›  Lieutenant Dan

python中的setTimeOut风格的click函数

  •  0
  • Lieutenant Dan  · 技术社区  · 7 年前
    def save_contact (self, driver):
         sleep(15)
         driver.find_element_by_css_selector("#publishButton").click()
    

    使用上面的命令;我正在尝试实现15秒后触发的单击功能。类似于JavaScript setTimeOut 功能-

    save_contact() 
    

    我知道这显然是不对的,但这是我在Python中得到的。目前看来这只会停止我的整个脚本/程序。在Python中可以这样做吗?

    0 回复  |  直到 7 年前
        1
  •  1
  •   pguardiario    7 年前

    你可以:

    driver.execute_script("window.setTimeout(() => document.getElementById('publishButton').click(), 15000)")