簡體   English   中英

為什么time.sleep()在循環內不起作用

[英]why does time.sleep() not working inside the loop

我有一個代碼,我試圖將數據從excel工作簿導入到鏈接。 但是,以下代碼在第一次執行循環時會引發錯誤

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import xlrd
workbook = xlrd.open_workbook("Book2.xlsx")
sheet = workbook.sheet_by_name("Sheet1")
sh1 = workbook.sheet_by_index(0)

i=0
while (i<2):
    logwork=driver.find_element_by_id("tempo-add-button")
    logwork.click()
    rownum=(i)`enter code here`
    rows = sh1.row_values(rownum)
    issue=driver.find_element_by_id("tempo-issue-picker-0-field")
    issue.send_keys(rows[0])
    issue.send_keys('\ue007')
    time=driver.find_element_by_id("time-0")
    time.send_keys(rows[2])
    desc=driver.find_element_by_id("comment-0")
    desc.send_keys(rows[1])
    log=driver.find_element_by_xpath("//button[@class='button-panel-button' and @accesskey='s']")
    log.click()
    i=i+1
    time.sleep(10)

預期的延遲時間為10秒,但低於錯誤。 請幫我 。 我瀏覽了之前提出的幾個查詢,但是沒有一個對我有幫助

AttributeError Traceback (most recent call last) <ipython-input-2-02342703a8f4> in <module>
     log.click()
     i=i+1
-->time.sleep(10)

AttributeError: 'WebElement' object has no attribute 'sleep'

問題是你設定的timeWebElement在線time=driver.find_element_by_id("time-0")變化的變量名,它應該是修復它

這里:

time=driver.find_element_by_id("time-0")

您正在使用WebElement實例覆蓋名稱time 使用其他名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM