使用send_keys方法上传一个文件福建,并进行提交操作,以下是完整代码:
首页自己创建两个被测网页:
1.uploadFile.html
Browse for a file to upload:
2.parse_file.html
import unittest
from selenium import webdriver
import time
import traceback
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException,NoSuchElementException
class MyTestCase(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path=’/python/driver/chromedriver’)
def test_uploadFileBySendKeys(self):
url=“file:///D:/upload/uploadFile.html”
self.driver.get(url)
try:
#创建显示等待对象
wait=WebDriverWait(self.dr