简体   繁体   中英

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

i have a code where i am trying to import the data from excel workbook to a link. however the below code throws the error when loop is executed for the first time

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)

expected is a delay of 10 secs but throwing below error. Please help me . i have browsed through several queries asked before but none of that helped me

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")变化的变量名,它应该是修复它

Here:

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

You are overwriting the name time with a WebElement instance. Use a different name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM