- input 类型
1、使用webdriver的send_keys方法:
def test_uploadFileBySendKeys(self):
url = "file:///Users/doudou/Desktop/six.html"
self.driver.get(url)
try:
# 创建显示等待的对象
wait = WebDriverWait(self.driver,10,0.2)
# 显示等待判断当前文件是否处于可被单击状态
wait.until(EC.element_to_be_clickable((By.ID,'file')))
except TimeoutException as e:
print(e)
except NoSuchElementException as e:
print(e)
except Exception as e:
print(e)
else:
# 查找属性为"file"文件上传框
fileBox = self.driver.find_element_by_id('file')
# 在文件上传框的路径框里输入要上传的文件路径"/Users/doudou/Desktop/six.html"
fileBox.send_keys("/Users/doudou/Desktop/six.html")
time.sleep(3)
# # 提交按钮
self.driver.find_element_by_id("filesubmit").click()
- 非Input类型