我有一个代码,我试图将数据从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'
答案 0 :(得分:4)
问题是您在第time
行的WebElement
到time=driver.find_element_by_id("time-0")
上设置了更改变量名称,应该对其进行修复
答案 1 :(得分:4)
这里:
time=driver.find_element_by_id("time-0")
您正在用time
实例覆盖名称WebElement
。使用其他名称。