input标签
- 先定位input标签,type='file'
- 使用send_keys上传文件
1. # 先点击,再上传 2. driver.find_element_by_name('file').click() 3. driver.find_element_by_name('file').send_keys(文件路径)
代码实例
1. # -*- coding: utf-8 -*- 2. # @Time : 2021/1/16 3. # @Author : 大海 4. 5. import time 6. from selenium import webdriver 7. 8. # 草料二维-码识别二维码获取网址 9. driver = webdriver.Chrome() 10. driver.maximize_window() 11. driver.get('https://cli.im/tools') 12. ele = driver.find_element_by_id('feature-item-upload') 13. driver.execute_script('arguments[0].scrollIntoView(false);', ele) 14. driver.execute_script("document.getElementById('feature-item-upload').click()") 15. ele.send_keys(r'二维码路径') 16. time.sleep(5) 17. url = driver.find_element_by_xpath("//*[@class='result-outer']/div").text 18. print(url) 19. driver.quit()